Eight things I found poking at AI Gateway
The gateway serves the right data. Somewhere between it and your code, prices, error types and audio formats get lost.
How I tested it
I wanted to use AI Gateway the way an app that depends on it would, and I didn't want to spend money doing it. That ended up mattering less than I thought. The model catalog is public, the real gateway still answers when your key is missing or wrong, and for everything else I ran a tiny local server that sends back the gateway's real responses, so I could see exactly what the AI SDK does with them.
Pricing data, error handling and the SDK's parsing are all reachable that way, and that's where most of the problems were. I found eight. The pattern across most of them is that the gateway sends the right data and something between it and your code loses it. Each one ends with what I'd change if I were on the gateway team.
1. getAvailableModels() throws away most of the pricing
The AI SDK has a documented way to read model pricing from code: gateway.getAvailableModels(). The docs page on models and providers has an example that loops over the result and prints each price. I ran that example as written against a copy of the real /v4/ai/config response, the same endpoint the SDK calls.
-- openai/whisper-1 Input: $0.0000000001/token Output: $0/token -- elevenlabs/music-v2 Input: $0/token Output: $0/token -- lines printed for 'Input tiers' (the example's tiered-pricing branch): 0 -- models in the raw response with input_tiers: 39
Whisper isn't free, and neither is music generation. The gateway knows that, since whisper's entry includes transcription_duration_cost_per_second: "0.0001". The SDK's response schema only keeps four pricing fields: input, output, and the two cache prices. Everything else gets stripped during parsing, including per-second audio and video prices, per-character speech prices, image prices and context-length tiers. Pick a model and compare:
What the gateway sends
- input
- "0.0000000001"
- output
- "0"
- transcription_duration_cost_per_second
- "0.0001"
What getAvailableModels() gives you
- input
- "0.0000000001"
- output
- "0"
The docs example prints:Input: $0.0000000001/tokenOutput: $0/token
1 field dropped, struck through on the left. The real price for this model is in one of them.
Across the whole catalog, 148 of 440 models lose at least one pricing field. For speech and realtime models it's all of them.
148 of 440 models lose pricing in the SDK
Models per type in /v4/ai/config, split by whether getAvailableModels() drops any of their pricing fields.
Show the data
| Type | Models | Lose pricing fields |
|---|---|---|
| Speech | 24 | 24 |
| Realtime | 10 | 10 |
| Video | 37 | 34 |
| Transcription | 16 | 14 |
| Image | 44 | 24 |
| Language | 246 | 39 |
| Evaluation | 26 | 2 |
| Embedding | 28 | 1 |
| Reranking | 9 | 0 |
There's a second, smaller thing in the same function. getAvailableModels() refuses to run without credentials and throws No authentication provided before sending anything, but the endpoint it calls returns the full 287 kB response with no auth at all. A model picker on a marketing page could just call it.
What I’d suggest: pass the pricing object through and type the extra fields, or at least keep them under a raw key. Then the docs example's tier branch, which already exists, would actually run.
2. pricing.input means something different per model type
Even in the raw data, the meaning of pricing.input depends on the model type.
| Model type | What pricing.input holds | Example |
|---|---|---|
| Language, embedding | Dollars per input token | 0.0000025 |
| Speech | A copy of the per-character price, in all 19 models that have one | 0.00004 |
| Transcription, billed per second | 0, 1e-10 or 2e-10, which look like placeholders | 0.0000000001 |
15 models have an empty pricing: {} in /v1/models, including both streaming transcription models. Music and sound-effect models are typed speech. None of this is wrong if you read the extra fields, but input is the field everyone reads first, and the docs label it per token.
What I’d suggest: either leave input out when it isn't a per-token price, or add a unit next to every price. A placeholder of 1e-10 is worse than no field, because it looks like a real number.
3. The list and detail endpoints disagree about ZDR
GET /v1/models lists everything, and GET /v1/models/{id} returns one model. I compared them for 117 models: every speech, transcription, embedding and reranking model, plus 40 random language models. 87 differed somehow. Most of that is harmless, since the detail endpoint adds an explicit "output": "0". These aren't harmless:
openai/gpt-6.1-sol-fast zdr list=some detail=all anthropic/claude-opus-5.5-fast regions list=['au', 'eu', 'jp', 'us'] detail=['us'] pricing keys only in list: ['regional', 'web_search']
ZDR (zero data retention) is a compliance answer, so "some" and "all" aren't interchangeable. Within the list itself, three Claude fast models list regions that have no regional price. And the SDK's config endpoint has 440 models while /v1/models has 516. The 76 missing ones are all the -fast and -batch variants, so a model picker built on the SDK can't offer them.
What I’d suggest: generate both endpoints from one source. If that already happens, then something between the source and one of them has a bug.
4. generateText turns a 401 into an error you can't catch by type
This is the one I'd want fixed first. I pointed the SDK at my local server returning the real gateway's 401 body and called five functions:
generateText AuthErr.isInstance=false statusCode=undefined cause=none streamText AuthErr.isInstance=false statusCode=undefined cause=none embed AuthErr.isInstance=true statusCode=401 cause=APICallError transcribe AuthErr.isInstance=true statusCode=401 cause=APICallError generateSpeech AuthErr.isInstance=true statusCode=401 cause=APICallError
The same 401 produces two kinds of error depending on which function you called. generateText and streamText route errors through a wrapGatewayError helper. In development it returns a plain Error that only has its name set to GatewayAuthenticationError. In production it returns an error named GatewayError, which GatewayError.isInstance still rejects. Either way the status code, the response body and the cause are gone.
Against the real gateway with a key that's set but wrong, the message says the same thing as when no key is set at all: set AI_GATEWAY_API_KEY. It also has ANSI color codes baked into message, so they end up in your JSON logs.
Documented
try {
await generateText({ model, prompt });
} catch (e) {
if (GatewayAuthenticationError.isInstance(e)) {
// never runs for generateText
}
}Actually works
} catch (e) {
// a string match on the name, no status code.
// In production the name is "GatewayError".
if (e instanceof Error &&
e.name === "GatewayAuthenticationError") {
}
}What I’d suggest: keep the original error as cause, and return a real GatewayAuthenticationError with the pretty message added on top. And only suggest setting the variable when no key was sent.
5. Speech output formats crash or get labeled as MP3
The option is called outputFormat in both generateSpeech and experimental_streamSpeech, but it takes a string in one and an object in the other. The streaming docs show { type: 'audio/pcm', rate: 24000 }. Pass that same object to generateSpeech from plain JavaScript and the request goes out and the audio comes back. Then the SDK calls .trim() on your object while labeling the result, and throws away audio you already paid for:
sent {"type":"audio/pcm","rate":24000} -> threw TypeError: outputFormat.trim is not a function elevenlabs/eleven-flash-v2.5 outputFormat="pcm_16000" -> result.audio.mediaType=audio/mp3 elevenlabs/eleven-flash-v2.5 outputFormat="ulaw_8000" -> result.audio.mediaType=audio/mp3 openai/tts-1 outputFormat="pcm" -> result.audio.mediaType=audio/pcm
The second problem doesn't need a typo. For any format string it doesn't recognize, the SDK guesses from the bytes, and raw PCM has no magic bytes, so it falls back to audio/mp3. That isn't even the registered type, which is audio/mpeg, and the SDK uses audio/mpeg itself when it detects real MP3. A player that trusts mediaType will try to decode raw PCM as MP3. This was against my local server, and I didn't confirm that the real gateway accepts pcm_16000, but the labeling happens in the SDK either way.
What I’d suggest: accept both shapes in both functions, check the type before sending, and return application/octet-stream when the format is unknown, not a guess.
6. transcribe() calls anything it doesn't recognize WAV
Same idea, other direction. transcribe() sniffs the audio you pass and sends a media type with it. WebM, M4A, OGG, FLAC and MP3 were all detected correctly. Here are the formats a phone or a Mac actually produces:
aiff (macOS / Logic export) -> mediaType sent: audio/wav caf (Core Audio, iOS) -> mediaType sent: audio/wav amr (Android voice memos) -> mediaType sent: audio/wav raw 16-bit PCM, no header -> mediaType sent: audio/wav with mediaType: "audio/x-caf" passed in -> sent: audio/wav
There's no mediaType option to override it. TypeScript rejects one, and plain JavaScript ignores it. The only workaround I found is to pass a URL with a custom download function that returns the type.
What I’d suggest: add mediaType?: string to transcribe(), and warn when sniffing falls back to the default.
7. Coding agent auth errors name the wrong env var
The gateway has endpoints for specific coding agents, /claude-code, /codex/v1 and /cursor/v1, so it knows which client is calling. With a bad token, all three say the same thing:
$ ANTHROPIC_AUTH_TOKEN=bogus → /claude-code/v1/messages {"error":{"message":"Authentication failed. Create an API key and set in AI_GATEWAY_API_KEY environment variable: https://vercel.com/d?to=…","type":"authentication_error"}}
Claude Code doesn't read AI_GATEWAY_API_KEY. Vercel's own Claude Code guide has you set ANTHROPIC_AUTH_TOKEN and an empty ANTHROPIC_API_KEY, so following the error message changes nothing. Send no auth at all and you get Missing Authorization header, with no link or next step.
While I was in there, I noticed the error bodies don't all look the same. One host returns five different shapes:
| Shape | Where |
|---|---|
| {error:{message,type}} | Every 401 |
| {error:{message,type,param,code:"…"}} | /v1/chat/completions validation errors and 404s, the shape the docs show for everything |
| {type:"error",error:{type,message}} | /v1/messages (Anthropic's shape, and documented) |
| {error:{type,message}} | /v1/responses validation errors |
| {error:{message,type,code:400}} | /v4/ai/*, where code is a number |
Validation also runs before auth, so with no key you can get tools.0: Invalid input for a tool missing input_schema. The error doesn't say what's invalid about it.
What I’d suggest: name the variable that each path's client actually reads. That's a lookup table with three rows.
8. A few docs examples don't run
I type-checked the TypeScript examples on six of the gateway docs pages. Most of the ones that failed just use variables from the surrounding text, which is fine. Three are real bugs:
gateway-provider__21.ts: Property 'total_used' does not exist on type 'GatewayCreditsResponse'. Did you mean 'totalUsed'? gateway-provider__23.ts: Property 'providerMetadata' does not exist on type 'TextStreamPart<ToolSet>'. gateway-provider__49.ts: ',' expected. prompt: 'Summarize this quarter's results'
The first one runs, it just prints Team total used: undefined credits. The third is an unescaped apostrophe, which a CI job that compiles the docs would catch on day one.
What's actually good
The catalog is fast, cacheable and public. It sends gzip, cache-control: public, open CORS, and a CDN hit on the full 586 kB list.
Catalog response time
Median of 20 sequential requests from the US east coast.
There are no duplicate IDs, and every one of the 516 entries has an id, type, pricing object, modalities and specs. The coding-agent model list drops exactly what the docs say it drops. Tool calls streamed through the gateway provider were assembled, parsed and executed correctly, and truncated tool JSON became a tool-error part, not a crash. Deprecations are loud: the old experimental_transcribe still works and logs a coded warning.
One more thing I noticed but can't call a bug. If a stream ends without a finish event, streamText resolves finishReason: "other" with empty usage and no error. That's defensible, but it means your code can't tell a dropped connection from a model that decided to stop.