Migrating the Responses API from OpenRouter to Sarvam
Last updated: October 23, 2026
This guide covers moving OpenRouter Responses API
calls to Sarvam’s POST /v2/responses.
For Chat Completions, see Migrating Chat Completion.
In short: both Responses APIs are stateless, so your history handling carries over. Change
base_url, api_key, and model, remove OpenRouter-only fields such as provider,
models, and plugins, and replace server tools like openrouter:web_search with your own
function tools.
Migration checklist
- Change
base_urltohttps://api.sarvam.ai/v2andapi_keyto your Sarvam key. - Replace each model ID using the model ID table.
- Remove OpenRouter-only fields:
provider,models,plugins, andstop(list). - Replace OpenRouter server tools with function tools you run yourself (Tools).
- On
glm5.3andglm5.3-flash, don’t send"max"; omittingreasoning.effortgivesmaxonglm5.3andhighonglm5.3-flash(Reasoning). - Set
max_output_tokens: it has no default cap on Sarvam. - If you use the
sarvamaiSDK, read the reply from themessageitem inoutput(quick start).
Quick start
Before (OpenRouter)
After (Sarvam)
Conversation history
Both APIs are stateless: send the whole conversation in input on every call. Code that
already does this for OpenRouter works unchanged. previous_response_id, store: true,
conversation, and background: true return 400 on Sarvam, as on OpenRouter.
Reasoning
Reasoning tokens count toward max_output_tokens, which has no default cap on Sarvam.
Tools
Sarvam’s Responses API supports function tools only, in the same flat Responses format:
{"type": "function", "name": ..., "parameters": ...}. OpenRouter server tools, such as
openrouter:web_search, return 400. Run those services from your own code and expose them as
function tools.
The function call round trip is the same as on OpenRouter: the model returns a
function_call item, you run the function, and you send back the call plus a
function_call_output item in the next request’s input. See the full example.
Fields to remove
Sarvam returns 400 with the field named for request fields it doesn’t support.
Parameter concept map
Full example
A function-calling loop that sends the call and its result back in input:
Common mistakes
Sending reasoning.effort: max to glm5.3
glm5.3 and glm5.3-flash return 400 for the literal string "max" on the Responses
API. Omit reasoning.effort instead: that gives max on glm5.3 and high on glm5.3-flash.
Leaving max_output_tokens unset
Sarvam doesn’t cap output by default, so a reasoning model can generate for a long time.
Set max_output_tokens.
Reading response.output_text with the sarvamai SDK
The shortcut exists in the openai package only. With sarvamai, read the message
item in output.
Expecting OpenRouter server tools to work
Server tools such as openrouter:web_search return 400. Call the service yourself and
expose it as a function tool.
See also
- Migration overview: base URL, auth, and model IDs
- Migrating Chat Completion from OpenRouter
- Responses API guide
- Responses API reference