Skip to main content
Your agent never holds a provider API key. It calls models through the AgentOS gateway, an OpenAI-compatible endpoint, with the invocation’s run token. The gateway routes the call to the environment’s provider, applies the environment’s guardrails, and records tokens, cost and latency on the run.

1. Name the models in agentos.yaml

Give each model a role under config.models. The value is the model’s name as the environment’s Models page lists it, <provider slug>/<model ID>:
agentos.yaml
Every model must exist on the Models page of the environment you deploy to, or the upload is refused. An admin adds providers and ticks the models agents may use; see Models and providers.

2. Call the gateway

On each invocation, context.llm.base_url is the gateway and context.config.models holds the names. Send the run token as x-agentos-run-token; the API key can be anything.
With the SDKs, inv.llm is the gateway with the token already attached: Other parameters (temperature, tools, …) go into the request body. Framework adapters give you a ready model for the OpenAI Agents SDK, Agno and the Vercel AI SDK; see Frameworks.
Create the model client inside the handler, per invocation, not at module level: it carries this invocation’s run token, which stops working when the invocation answers.

Which names to send

Send exactly the names in config.models. A run only reaches its own environment’s models, so a name from another environment, a bare model ID (claude-sonnet-4-5) or a provider path answers 400. GET {base_url}/models lists the environment’s models with the environment’s number in front (3/anthropic/claude-sonnet-4-5). Send them without that prefix.

Supported routes

The run token reaches these gateway routes; every other route answers 403.

What a call can’t carry

The gateway decides which provider and credentials a call uses, so a request is refused with 400 naming the key when it carries:
  • more than one model (a , in the model name);
  • routing settings: fallbacks, context_window_fallbacks, content_policy_fallbacks, router_settings_override, specific_deployment, model_info;
  • credentials: api_key, aws_access_key_id and the like.

When a guardrail blocks a call

The environment’s guardrails check each call. A block fails only that call with HTTP 400; the run goes on and your code decides what to do — try differently, skip the step, or ask a person:
Branch on agentos_guardrail. The SDKs raise GuardrailBlocked (with guardrail, at and hit); left uncaught, the run fails with blocked_by_guardrail. A route a guardrail can’t be enforced on answers 403 agentos_forbidden. Streams, framework behaviour and every other case are on the Guardrails page.

What is recorded

Each call becomes an llm.call event on the run’s timeline with its model, tokens, cost and latency, and the tools the model asked for become tool.call events. The run’s usage adds them up (llm_calls, input_tokens, output_tokens, cost), and the Dashboard and Models page show the totals; see Metrics.
Prompts and responses are never stored. Only the model, token counts, cost, latency and the names of the tools the model asked for are kept.

Next steps

Streaming answers

Stream a model’s answer straight to your caller.

Evals

Compare models and prompts on a dataset without a new build.