Description
When AI Gateway credits are depleted (zero balance), all requests are blocked - including those that should use BYOK (Bring Your Own Key) credentials. This happens regardless of whether BYOK is configured via:
- Dashboard integrations (with working "Test Key" verification)
- Programmatic
providerOptions.byokin code
Expected Behavior
When BYOK credentials are configured (either via dashboard or providerOptions.byok), requests should be routed directly to the provider using those credentials, without requiring AI Gateway credits.
The documentation states:
"Using your own credentials with an external AI provider allows AI Gateway to authenticate requests on your behalf with no added markup."
This implies BYOK should bypass the credit system entirely.
Actual Behavior
All requests fail with:
Insufficient funds. Please add credits to your account to continue using AI services.
Even when:
- BYOK integrations are configured in dashboard AND "Test Key" passes
providerOptions.byokis explicitly set in the request
Reproduction Steps
- Configure BYOK integration in Vercel Dashboard (AI Gateway → Integrations)
- Verify the key works using "Test Key" feature ✓
- Deplete AI Gateway credits to $0
- Make a request using
createGateway():
import { createGateway, generateText } from "ai"; const gateway = createGateway(); // Method 1: Relying on dashboard BYOK config const response1 = await generateText({ model: gateway("anthropic/claude-3-5-haiku-latest"), prompt: "Hello", }); // Method 2: Explicit BYOK via providerOptions const response2 = await generateText({ model: gateway("anthropic/claude-3-5-haiku-latest"), prompt: "Hello", providerOptions: { gateway: { byok: { anthropic: [{ apiKey: process.env.ANTHROPIC_API_KEY }], }, }, }, });
Both fail with "Insufficient funds" error.
Verification
The API keys are valid - direct provider calls work:
import { anthropic } from "@ai-sdk/anthropic"; import { generateText } from "ai"; // This works perfectly const response = await generateText({ model: anthropic("claude-3-5-haiku-latest"), prompt: "Hello", });
Environment
aipackage version: 6.0.0-beta.128@ai-sdk/gateway: latest- Node.js: v25.2.1
Impact
Users who:
- Set up BYOK to avoid Vercel credit costs
- Have valid provider API keys with available quota
- Run out of AI Gateway credits (even accidentally)
...are completely blocked from using AI Gateway, defeating the purpose of BYOK.
Suggested Fix
The credit check should be bypassed when:
- Valid BYOK credentials are configured in dashboard for the requested provider
providerOptions.byokcontains valid credentials for the requested provider
The gateway should only require credits when using Vercel's system credentials.