API documentationIntegrationsVercel AI SDK

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.

npm install ai @ai-sdk/openai-compatible
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 browserkeep the key in a server-side env var — never expose it with a NEXT_PUBLIC_ prefix.
  • structured output errorsgenerateObject depends on the model's response_format support — check the model card first.

Troubleshooting

The failures below account for nearly every unsuccessful first connection, whatever the tool.

StatusSymptomFix
401Key missing, mistyped, or deletedRe-copy the key from Keys and confirm which header your tool sends — Authorization: Bearer or x-api-key.
403No credits on the account (INSUFFICIENT_BALANCE)Add credits first. Verify buttons and test prompts inside tools fire real requests.
404Model not foundSend the bare model ID exactly as listed on Models — no provider/ prefix in the request body.
429Concurrency or key spend limit reachedLower 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.