AI Gateway
Use Astro-provided LLM access without managing your own provider keys
Set one line in your spec and your agent gets a managed API key for calling supported models — no provider account, no API keys to store, no key rotation to manage. 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:
This generates astro_ai_gateway: true in the spec and agent code that reads the injected env vars — no provider key to configure. To enable the gateway on an existing agent, add the flag to astropods.yml by hand:
On ast deploy (and ast dev), your agent container receives two environment variables:
Calling the gateway
The OpenAI-compatible API lives under the /v1 path, so set your client’s base URL to ${ASTRO_GATEWAY_URL}/v1. Everything else is a standard OpenAI-style request — pass one of the supported models as model and authenticate with ASTRO_GATEWAY_API_KEY as a bearer token.
Append /v1 to ASTRO_GATEWAY_URL. The env var is the host only (e.g. https://aig.example); the OpenAI-compatible endpoints are served under /v1 (/v1/chat/completions, /v1/embeddings). Pointing a client at the bare host returns 404.
For Mastra: the AI-SDK provider returned by createOpenAI is what Agent.model: accepts, so the rest of your Agent / Workflow / Tool definitions stay the same.
Mastra needs an AI SDK v5+ model. Add @ai-sdk/openai at v2 or later to your own package.json. Version 1.x produces an AI SDK v4 model (specificationVersion: "v1") that Mastra’s stream() rejects with AGENT_STREAM_V1_MODEL_NOT_SUPPORTED. This can be newer than the @ai-sdk/openai version Mastra pins internally, so install it explicitly rather than relying on the transitive one.
Supported models
Pass any of these strings as model on the SDK call:
All chat models are called the same way — swap the model string. titan-embed-text-v2 is an embeddings model (use the embeddings endpoint, below).
Streaming
Set stream: true to receive tokens incrementally as they’re generated.
Embeddings
Use titan-embed-text-v2 on the embeddings endpoint for RAG and vector search. It returns a 1024-dimension vector per input.
Images (vision)
pixtral-large accepts image input alongside text. Pass the image as a base64 data URI in an image_url content block — the gateway forwards the image bytes to the model, so remote URLs are not fetched server-side.
Structured output
Prompting for a JSON object and parsing it (with a fallback for the occasional non-JSON reply) is a portable way to get structured output that works regardless of which structured-output features a given model exposes through the gateway.
Local development
ast dev handles the gateway automatically. Run:
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:
Your agent code reads ASTRO_GATEWAY_API_KEY for gateway calls and OPENAI_API_KEY for the BYOK provider.
Errors and limits
The gateway returns standard OpenAI-style error responses. Common cases:
What it doesn’t cover
- Provider-native SDKs and prefixes. The gateway serves models from several providers (Anthropic Claude, Amazon Nova/Titan, Mistral), but you call them all through the OpenAI-compatible API by their gateway id (for example
claude-sonnet-4-6), not with a provider prefix such asanthropic/. - Image generation. No image-generation models are offered. Image input (vision) is supported by
pixtral-large. - Bring-your-own-model. Adding new models or fine-tunes to the gateway isn’t self-serve; reach out to support.