Skip to navigation

Migrating from OpenRouter: Overview

View as Markdown

Last updated: October 23, 2026

OpenRouter and Sarvam’s /v2 API both speak the OpenAI Chat Completions format, so most migrations are a base URL, key, and model ID change. This page covers those setup changes. The Chat Completion and Responses API guides cover request fields, reasoning, tools, and the OpenRouter-only features to remove.

Quick start

Change the client and the model ID. Use the openai package you already have, or Sarvam’s own SDK (SDKs & Libraries).

from openai import OpenAI
client = OpenAI(
api_key="YOUR_OPENROUTER_API_KEY",
base_url="https://openrouter.ai/api/v1",
)
response = client.chat.completions.create(
model="moonshotai/kimi-k3",
messages=[{"role": "user", "content": "Hello!"}],
)

For requests made directly over HTTP, change the URL, the auth header, and the model ID:

curl https://openrouter.ai/api/v1/chat/completions \
-H "Authorization: Bearer YOUR_OPENROUTER_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "z-ai/glm-5.3-flash",
"messages": [{"role": "user", "content": "Explain UPI in two sentences."}],
"max_tokens": 1000
}'

Sarvam also accepts Authorization: Bearer <key>, which is what the openai package sends, so you don’t need to change how your client authenticates. Create a key in the Sarvam dashboard.

Zero-code switch

The openai package for Python and JavaScript reads its endpoint and key from the OPENAI_BASE_URL and OPENAI_API_KEY environment variables when you create the client without them. If your app does that, and reads the model ID from configuration, you can switch without changing code:

export OPENAI_BASE_URL="https://api.sarvam.ai/v2"
export OPENAI_API_KEY="YOUR_SARVAM_API_KEY"
from openai import OpenAI
client = OpenAI() # picks up OPENAI_BASE_URL and OPENAI_API_KEY

Then set your configured model to a Sarvam model ID. If your requests send OpenRouter-only fields, remove them as described in the Chat Completion guide.

Base URL and auth

OpenRouterSarvam
Base URLhttps://openrouter.ai/api/v1https://api.sarvam.ai/v2
Chat CompletionsPOST /chat/completionsPOST /chat/completions
ResponsesPOST /responsesPOST /responses
Auth headerAuthorization: Bearer <key>api-subscription-key: <key> or Authorization: Bearer <key>
Attribution headersHTTP-Referer, X-OpenRouter-TitleNot needed; you can leave them in
Auth failure status401403
Out of credits402402

Model IDs

Sarvam serves each model directly, so there are no provider prefixes, :free, :nitro, or :floor suffixes, or dated slugs to choose between.

OpenRouter modelSarvam modelStatus on Sarvam
z-ai/glm-5.3glm5.3GA
z-ai/glm-5.3-flashglm5.3-flashGA
google/gemma-4-31b-itgemma4GA
deepseek/deepseek-v4.1-flash-1017deepseekv4.1-flash-1017Beta
deepseek/deepseek-v4.1-flash-1017deepseekv4.1-flash-1017Beta
deepseek/deepseek-v4-pro-0813deepseekv4-proBeta
moonshotai/kimi-k3kimi-k3Beta
xiaomi/mimo-v2.6-flashmimo-v2.6-flashBeta
xiaomi/mimo-v2.6-promimo-v2.6-proBeta

Sarvam’s deepseekv4-pro is the 0813 snapshot. OpenRouter’s plain deepseek/deepseek-v4-pro is the earlier 0423 snapshot, so outputs can differ after you switch.

Model IDs are case-sensitive. An unknown ID returns 404 not_found_error. GET /v2/models lists the available models. Beta models need per-key access: without it, they return 400 invalid_request_error, even though the list shows them. Contact us to request access.

Models not on Sarvam

If you use a model that Sarvam doesn’t serve, start with the closest one below, then test it on your own prompts before switching traffic. These are suggestions, not drop-in equivalents.

If you useTry on SarvamWhy
GLM-5.3 Primeglm5.3Same GLM-5.3 generation.
GLM-5.3 FlashXglm5.3-flashSame fast GLM-5.3 variant family, with image input.
Earlier GLM (GLM-5.2, GLM-5.1, GLM-5, GLM-4.x)glm5.3Newer generation of the same family. For image input, use glm5.3-flash.
DeepSeek V4 Flash (any snapshot), DeepSeek V3.xdeepseekv4.1-flash-1017The DeepSeek Flash model Sarvam serves.
DeepSeek V4 Pro (April 2026 snapshot), DeepSeek R1deepseekv4-proSarvam serves the newer 0813 snapshot.
Kimi K2, K2.5, K2.6, K2.7 Code, K2 Thinkingkimi-k3Newer Kimi generation, with a longer 1M context.
MiMo V2.5, MiMo V2.6 Pro UltraSpeed, MiMo V2.6 Pro-RLmimo-v2.6-pro or mimo-v2.6-flashCurrent MiMo generation, with image, audio, and video input.
Gemma 3, Gemma 4 26Bgemma4Gemma 4 31B: image input, a 256K context window, and reasoning (off by default).

For other model families, such as Qwen, Llama, gpt-oss, or MiniMax, choose by what you need:

If you needTry on Sarvam
Indian-language qualitysarvam-105b
The lowest costmimo-v2.6-flash
Image inputglm5.3-flash, kimi-k3, gemma4, or the MiMo models
Audio inputmimo-v2.6-flash or mimo-v2.6-pro
Video inputmimo-v2.6-flash or mimo-v2.6-pro (chat only)
The hardest coding and agent tasksglm5.3 or deepseekv4-pro
Fast answers without reasoningmimo-v2.6-flash with thinking off, or gemma4

Media input and request size

Sarvam accepts images, audio, and video only as inline base64 data URIs. Remote http(s) URLs return 400 on every model, even where your current provider fetches them for you, so download the file and encode it before sending.

MediaModelsChat CompletionsResponses
ImageModels with image input, such as gemma4, glm5.3-flash, kimi-k3, and the MiMo modelsimage_url partinput_image part
Audiomimo-v2.6-flash, mimo-v2.6-proinput_audio part (wav or mp3), or an audio_url part with a data URI (WAV, MP3, FLAC, OGG, Opus)input_audio part (wav or mp3)
Videomimo-v2.6-flash, mimo-v2.6-pro, and kimi-k3 (beta, short clips)video_url partNot supported
import base64
def data_uri(path: str, mime: str) -> str:
with open(path, "rb") as f:
return f"data:{mime};base64," + base64.b64encode(f.read()).decode()
image_part = {"type": "image_url", "image_url": {"url": data_uri("chart.png", "image/png")}}
video_part = {"type": "video_url", "video_url": {"url": data_uri("clip.mp4", "video/mp4")}}

Request bodies, including base64 media, are limited to 40 MiB on kimi-k3 and the MiMo models, and 10 MiB on other models. Larger requests return 413 with the limit in the message. Base64 adds about 33%, so about 30 MB of raw media fits in a 40 MiB request.

Errors and rate limits

Sarvam returns 403 (not 401) for a missing or invalid key, 429 when you exceed a rate limit, and 503 when a model is overloaded. Retry 429 and 503 with backoff. Limits apply per API key. See Errors & Troubleshooting and Credits & Rate Limits.

See also