Set up your agent
Bring an agent you already run under Liyagent governance by registering it as self-managed and routing its model calls through the gateway.
After reading this page you will be able to:
- Register an existing agent as self-managed
- Issue it a gateway credential
- Apply a budget, a guardrail and a policy to it
Prerequisites
- A running Liyagent instance and an account with the admin or owner role.
- An agent that uses an OpenAI-compatible client (most frameworks do).
Steps
- Open Agents › All agents, choose + Create agent, then Self-managed.
- Fill in the form:
Section Notes 01 Identity Name and Description. The Agent id is made from the name (lowercase letters, digits and hyphens) and cannot be changed later. 02 Access Who may use it: the access policy created with it. 03 Tags Under Advanced: key=valuepairs, comma-separated, used for cost chargeback, for exampleteam=hr,env=prod. - Choose Create and issue credentials. The agent is registered (
PUT /api/gateway/agents/{agent_id}) and a credential is issued (POST /api/agents/{agent_id}/credentials). The page shows itsclient_id,client_secret, the token URL and the AI Gateway base URL. Copy the secret now: it is shown once. Store it in your agent's secret manager. Credentials last 90 days by default. Issue more, or revoke one, on the agent's Credentials view (Create credential). - In your agent, get an access token with the OAuth client-credentials grant at
POST /api/gateway/oauth/token. A token lasts one hour. Get a new one when it expires. - Point the agent's OpenAI client at the gateway: base URL
https://<your-host>/api/gateway/v1, API key the access token. Chat completions go toPOST /api/gateway/v1/chat/completions.import httpx from openai import OpenAI HOST = "https://ticketiq.example.com" tok = httpx.post(f"{HOST}/api/gateway/oauth/token", data={ "grant_type": "client_credentials", "client_id": CLIENT_ID, "client_secret": CLIENT_SECRET}).json()["access_token"] client = OpenAI(base_url=f"{HOST}/api/gateway/v1", api_key=tok) bound = client.models.list().data[0].id # the model this agent is bound to client.chat.completions.create(model=bound, messages=[{"role": "user", "content": "hello"}]) - Make one call and open the agent's Cost & Usage tab: the call is there with tokens and cost.
Note
A long-lived static token also exists for older integrations: POST /api/gateway/agents/{agent_id}/token mints one (issuing again replaces it), and DELETE revokes it. Prefer the client-credentials flow above.
Put controls around it
- Budget: add a scoped budget with scope kind agent on Budgets. See Budgets.
- Guardrail: bind a guardrail set to the agent. See Create a guardrail.
- Policy: restrict what it may call with a Cedar policy or the Read only / Sandboxed templates. See Access.
Tip
You can switch an agent between managed and self-managed later with POST /api/gateway/agents/{agent_id}/convert.