OhMyGPT

Migrate from OpenRouter

Switch OpenRouter code to OhMyGPT by changing the base URL and key; your SDK code keeps working.

Switching takes two changes: the base URL and the key. Your OpenAI SDK code, streaming, tool calls, structured output, the provider object and your app attribution headers keep working as they are. Every response then tells you its exact cost, and the free ohmygpt/mock model lets you check the switch before you spend anything.

1. Change the base URL and key

BeforeAfter
Base URLhttps://openrouter.ai/api/v1https://api.ohmygpt.com/v1
KeyOpenRouter keyOhMyGPT key from API keys
import os

from openai import OpenAI

client = OpenAI(
    base_url="https://api.ohmygpt.com/v1",
    api_key=os.environ["OHMYGPT_API_KEY"],
)

completion = client.chat.completions.create(
    model="ohmygpt/mock",
    messages=[{"role": "user", "content": "Hello"}],
)
print(completion.choices[0].message.content)
This is a mock reply from OhMyGPT. Your integration works; switch to a real model when ready.

The mock is free and is available once your account has been topped up. When it answers, your URL and key are right.

2. Set the model IDs

Model IDs use the same creator/model form. Many are identical; others use a different creator name or a hyphen in the version:

OpenRouterOhMyGPT
openai/gpt-5.4-nanoopenai/gpt-5.4-nano
anthropic/claude-sonnet-4.6anthropic/claude-sonnet-4-6
x-ai/grok-4.7xai/grok-4.7
z-ai/glm-5.3zhipu/glm-5.3
moonshotai/kimi-k2.6moonshot/kimi-k2.6

List every ID with:

curl -s https://api.ohmygpt.com/v1/models | jq -r '.data[] | select(.available) | .id'

Prices are on the Models page. If an ID is off, the response is a 404 that names it:

{
  "error": {
    "message": "The model `anthropic/claude-sonnet-4.6` does not exist. List available models with `GET /v1/models`.",
    "type": "not_found_error",
    "param": "model",
    "code": "model_not_found"
  }
}

What keeps working

  • The provider object on Chat Completions, Responses and Messages, with order, only, ignore, allow_fallbacks, sort (price, latency or throughput, as a string or as {"by": "price"}), max_price (prompt, completion, image and request), zdr and data_collection. zdr and data_collection go by each provider's own published policy for API traffic, and a provider whose policy is unclear doesn't qualify. OpenRouter's provider slugs such as amazon-bedrock and google-vertex work as they are; each model lists its own under providers[].provider in GET /v1/models. See Provider Routing.
  • openrouter/auto and its auto-router plugin (allowed_models, excluded_models, cost_tier). See Auto Router.
  • App attribution headers: HTTP-Referer, X-OpenRouter-Title (or X-Title) and X-OpenRouter-Categories are read as they are. See App Attribution.
  • Streaming, tool calls and structured output (response_format with a JSON schema) in the standard OpenAI shapes.
  • The reasoning object on Chat Completions (effort, max_tokens, enabled), turned into each model's own thinking setting. See Thinking.
  • Usage in every non-streaming response. Chat Completions streams report usage when you set "stream_options": {"include_usage": true}, as on OpenAI, or OpenRouter's "usage": {"include": true}.
  • Usage accounting. With "usage": {"include": true}, usage also carries cost, is_byok and cost_details in USD. See Check the cost of each request.

Update these if your code uses them

If your code sendsDo this on OhMyGPT
A :floor model suffixUse the plain model ID with "provider": {"sort": "price"}
A :nitro model suffixUse the plain model ID with "provider": {"sort": "throughput"}
Another model suffixUse the plain model ID
A models fallback list that names other modelsRemove it; the request is rejected with a 400 that names models. OhMyGPT already fails over across a model's providers automatically; see Reliability. A list that holds only the requested model is accepted
Non-empty transforms, or routeRemove them; the request is rejected with a 400 that names the field
provider fields such as quantizations, region or max_price.audioRemove them; a field that would change routing is rejected with a 400 that names it in param. Use provider.only to pick the exact providers you want

Check the cost of each request

Every response carries X-Request-ID. Non-streaming responses also carry X-Cost-Credits, the exact charge in Credits; streams send it as an SSE comment line : x-cost-credits: N before the final event. Usage lists every request with its cost, and Costs explains Credits.

Send OpenRouter's "usage": {"include": true} and usage also carries the charge in USD, as on OpenRouter. Chat Completions streams put it on the final usage chunk, the last one that carries usage and no content; Responses streams put it in response.completed:

"usage": {
  "prompt_tokens": 1000,
  "completion_tokens": 500,
  "total_tokens": 1500,
  "cost": 0.006,
  "is_byok": false,
  "cost_details": {
    "upstream_inference_cost": null,
    "upstream_inference_prompt_cost": 0.002,
    "upstream_inference_completions_cost": 0.004
  }
}

cost is the same charge as X-Cost-Credits (1 USD = 250,000 Credits). upstream_inference_prompt_cost, upstream_inference_completions_cost and, when the request used hosted tools such as web search, server_tool_cost add up to cost; Responses names the first two upstream_inference_input_cost and upstream_inference_output_cost. upstream_inference_cost is what your own provider key paid when you bring your own key, and null otherwise. With your own key, cost is the service fee and the split is left out. The request receipt itemizes the same charge line by line.

Use the Anthropic and Gemini SDKs too

The same key also works with the Anthropic Messages API at /v1/messages and the Gemini API at /v1/models/{model}:generateContent. Code written for Anthropic's or Google's SDK can call OhMyGPT without changing format. The protocol table lists each SDK's base URL.

Was this page helpful?

Still stuck? Live chat · [email protected] · Telegram group