Vercel AI SDK
TypeScript framework · Chat Completions
The official openai-compatible provider package points the whole SDK at KoRouter — one createOpenAICompatible call, then every helper just works.
Base URL · OpenAI-compatible
https://korouter.ai/v1
Plus an API key from Keys and a bare model ID from Models. Every price on the catalog sits below the provider's official rate — pay as you go.
Setup
Use the OpenAI-compatible provider package and point it at KoRouter. The same provider instance works with generateText, streamText, and the rest of the SDK.
import { createOpenAICompatible } from "@ai-sdk/openai-compatible";
import { generateText } from "ai";
const korouter = createOpenAICompatible({
name: "korouter",
baseURL: "https://korouter.ai/v1",
apiKey: process.env.KOROUTER_API_KEY,
});
const { text } = await generateText({
model: korouter("model-name"),
prompt: "Hello",
});
console.log(text);Verify
Run the script with the env var set. The text prints and the request appears on Usage.
If it fails
- key in the browser — keep the key in a server-side env var — never expose it with a
NEXT_PUBLIC_prefix. - structured output errors —
generateObjectdepends on the model'sresponse_formatsupport — check the model card first.
Troubleshooting
The failures below account for nearly every unsuccessful first connection, whatever the tool.
| Status | Symptom | Fix |
|---|---|---|
| 401 | Key missing, mistyped, or deleted | Re-copy the key from Keys and confirm which header your tool sends — Authorization: Bearer or x-api-key. |
| 403 | No credits on the account (INSUFFICIENT_BALANCE) | Add credits first. Verify buttons and test prompts inside tools fire real requests. |
| 404 | Model not found | Send the bare model ID exactly as listed on Models — no provider/ prefix in the request body. |
| 429 | Concurrency or key spend limit reached | Lower parallel requests, or raise the key's spend limit, then retry with backoff. |
The full status-code table, retry guidance, and error envelopes are in Errors & limits. Still stuck? Email support@korouter.ai with the tool name, the model ID, and the exact error text.
Other tools
Free to sign up, no monthly fee — pay as you go with credits.