AI Gateway

AI Gateway

Use Astro AI-provided LLM access without managing your own provider keys

View as Markdown

Set one line in your spec and your agent gets a managed API key for calling supported models. The gateway is OpenAI-API-compatible, so it works with the SDKs and frameworks you already use.

Quick start

Scaffold a new agent wired to the gateway in one step:

ast create my-agent --model gateway

This generates a gateway model in the spec and agent code that reads the injected env vars, with no provider key to configure. To enable the gateway on an existing agent, declare a model with provider: gateway in astropods.yml and list the models you want to choose between:

models:
default:
provider: gateway
models: [claude-sonnet-4-6, claude-haiku-4-5]

The models list is a menu of options. At deploy time, in the web console and CLI, you pick one, and it is injected as MODEL_<NAME> (here MODEL_DEFAULT). Your agent code reads the model id from that env var.

The agent.astro_ai_gateway: true boolean is deprecated in favor of a provider: gateway model. It still works (it enables the gateway with no deploy-time model selection), but declaring a gateway model is preferred and lets you pick the model at deploy.

Injected environment variables

On ast deploy (and ast project), your agent container receives:

Env varPurpose
ASTRO_GATEWAY_URLGateway host (stable). Append /v1 for the OpenAI-compatible API.
ASTRO_GATEWAY_API_KEYBearer credential (stable). Treat as a secret.
MODEL_<NAME>The model chosen at deploy for the gateway entry <name> (e.g. MODEL_DEFAULT).

Local development

ast project handles the gateway automatically. Run:

ast login
ast project

Your local agent container receives the same ASTRO_GATEWAY_* env vars it would have in production. Code written against those env vars works identically in dev and prod.

Run ast login first if you haven’t. The gateway is account-scoped, so the CLI needs to know who you are.

Mixing with your own keys

astro_ai_gateway: true is independent of any models you declare. You can use the gateway for some calls and your own provider key for others:

agent:
image: my-agent:latest
astro_ai_gateway: true # gateway-managed models
models:
custom-fine-tune:
provider: openai # your own OpenAI key for a specific use case

Your agent code reads ASTRO_GATEWAY_API_KEY for gateway calls and OPENAI_API_KEY for the bring-your-own-key (BYOK) provider.

Next steps