Gateway quickstart
Get Gateway access, create a key, and point Claude Code, Codex, Cursor, the OpenAI or Anthropic SDK, or curl at https://api.agentlab.cresclab.com.
Before you start#
- Open the Gateway Sign up in the Agent Lab console and open AI Gateway in your workspace. If the Gateway is not on yet, a workspace owner turns it on from that page with Turn on AI Gateway, on the Free plan's quota; other members see which owner to ask.
- Create a key On the Get started tab, select Create API key and give it a name. The key is shown once; copy it now.
- Pick a client Follow one of the sections below. The console's Get started tab shows the same steps with your key and your workspace's models filled in.
Every example reads the key from the AGENTLAB_API_KEY environment variable:
export AGENTLAB_API_KEY="<your API key>"Model names come from GET /v1/models, which lists auto and every model your workspace allows. The names below are examples.
Claude Code#
Claude Code speaks Anthropic Messages and adds /v1/messages itself, so its base URL has no /v1. It checks the model name before sending, so it keeps a Claude model name and asks for auto with a header.
export ANTHROPIC_BASE_URL=https://api.agentlab.cresclab.com
export ANTHROPIC_AUTH_TOKEN=$AGENTLAB_API_KEY
export ANTHROPIC_MODEL=claude-sonnet-5-5
export ANTHROPIC_CUSTOM_HEADERS="X-AgentLab-Routing: auto"
export ANTHROPIC_DEFAULT_HAIKU_MODEL=claude-haiku-5-5
claudeLeave out the ANTHROPIC_CUSTOM_HEADERS line to always use the model you named. The haiku line sends Claude Code's small background calls to a cheap model.
Codex#
Codex speaks OpenAI Responses. Add a provider to ~/.codex/config.toml:
model = "gpt-5.6-luna"
model_provider = "agentlab"
[model_providers.agentlab]
name = "Agent Lab"
base_url = "https://api.agentlab.cresclab.com/v1"
wire_api = "responses"
env_key = "AGENTLAB_API_KEY"
http_headers = { "X-AgentLab-Routing" = "auto" }Then run it:
codexRemove the http_headers line to always use the model you named.
Cursor#
Cursor speaks OpenAI Chat Completions. It sends each request from Cursor's servers, not from your computer, which is why it needs the Gateway's public address. Only chat uses the Gateway; Tab completion keeps using Cursor's own models.
- Open the model settings In Cursor, open Cursor Settings › Models.
- Enter the key Under API Keys, paste your Gateway API key into OpenAI API Key and turn it on. Cursor keeps the key itself; it does not read
AGENTLAB_API_KEY. - Point it at the Gateway Turn on Override OpenAI Base URL and enter
https://api.agentlab.cresclab.com/v1. - Add a model Add
auto(orauto:cost/auto:quality), or a model by name such asgpt-5.6-luna, turn it on, and pick it in the chat's model menu.
Before you rely on it:
autokeeps one model for the whole Agent turn. Cursor cannot add theX-AgentLab-Routingheader and does not need to: every later step of an Agent turn (one that only adds tool results) answers with the modelautochose for that turn's first step.- Pick a model that isn't Claude or Gemini. Cursor sends names that start with
claude-orgemini-through its own Anthropic and Google settings, not to this address. - The override is not per model. While it is on, Cursor sends its other models, apart from Claude and Gemini, to the Gateway too. Turn it off to use them through Cursor again.
- Very long Agent chats are refused. One request carries at most 100 messages, 100 tools and 1 MiB; past that the Gateway answers 400
invalid_inference_request. Start a new chat. - Your Cursor plan must allow your own API keys. Cursor's Plus plan does not, a Teams or Enterprise admin can turn them off, and on those plans Cursor adds its own per-token rate to these requests. See Cursor's Bring your own API key.
OpenAI SDK#
pip install openaiimport os
from openai import OpenAI
client = OpenAI(base_url="https://api.agentlab.cresclab.com/v1", api_key=os.environ["AGENTLAB_API_KEY"])
reply = client.chat.completions.create(
model="auto",
messages=[{"role": "user", "content": "Hello"}],
)
print(reply.model, reply.choices[0].message.content)reply.model is the model that answered.
Anthropic SDK#
pip install anthropicimport os
from anthropic import Anthropic
client = Anthropic(base_url="https://api.agentlab.cresclab.com", api_key=os.environ["AGENTLAB_API_KEY"])
reply = client.messages.create(
model="auto",
max_tokens=1024,
messages=[{"role": "user", "content": "Hello"}],
)
print(reply.model, reply.content[0].text)curl#
Chat Completions:
curl https://api.agentlab.cresclab.com/v1/chat/completions \
-H "Authorization: Bearer $AGENTLAB_API_KEY" \
-H "Content-Type: application/json" \
-d '{"model": "auto", "messages": [{"role": "user", "content": "Hello"}]}'Anthropic Messages:
curl https://api.agentlab.cresclab.com/v1/messages \
-H "Authorization: Bearer $AGENTLAB_API_KEY" \
-H "anthropic-version: 2023-06-01" \
-H "Content-Type: application/json" \
-d '{"model": "auto", "max_tokens": 1024, "messages": [{"role": "user", "content": "Hello"}]}'OpenAI Responses:
curl https://api.agentlab.cresclab.com/v1/responses \
-H "Authorization: Bearer $AGENTLAB_API_KEY" \
-H "Content-Type: application/json" \
-d '{"model": "auto", "input": "Hello"}'Tag requests#
To see spend by team, feature or customer, add the X-AgentLab-Metadata header with one JSON object of string values, such as {"team": "support"}. It works with every endpoint above. See tags for the limits and where they show up.
Check it worked#
Open AI Gateway › Usage in the console. The request is listed with its key, the model that answered and its cost. If a request was refused, its code is in Errors.