Small, inspectable examples for the OpenAI SDK, Anthropic SDK, Claude Code, and curl. KeepRouter model IDs and enabled routes can change; choose an exact ID from the live model catalog before using a paid model.
| Your task | Start here |
|---|---|
| Make a first chat request with the published free model | Quickstart and the Python or Node OpenAI SDK example |
| Move an OpenAI or OpenRouter client | Credential-free migration checker, then review the migration starter source |
| Configure Claude Code with a Claude model | Claude Code guide and base URL settings |
| Diagnose a failed request | Error reference |
| Estimate a paid model's usage cost | Live model catalog and cost calculator |
The migration checker runs in your browser. Paste only configuration with credentials and private request content removed. It does not translate OpenRouter model slugs or provider-specific fields automatically; select a current KeepRouter model ID and test the actual route. The separate migration starter repository has dry-run Python and Node examples for a larger migration.
Create a key scoped to free using the quickstart. Set KEEPROUTER_KEY in your own shell or secret manager; never put a real key in source control. Install the SDK with pip install openai or npm install openai.
import os
from openai import OpenAI
client = OpenAI(
base_url="https://keeprouter.com/v1",
api_key=os.environ["KEEPROUTER_KEY"],
)
response = client.chat.completions.create(
model="free",
messages=[{"role": "user", "content": "Hello"}],
)
print(response.choices[0].message.content)Run the Python, Node, or curl version. These examples use Chat Completions; a model being listed in the catalog does not mean it supports every API route. For a paid model, create a key with that model in its scope and check its published price and endpoint first. The OpenAI SDK setup guide explains the /v1 base URL and common 401/404 mistakes.
The Anthropic SDK examples use the Messages API with a Claude model. They require a key scoped to the selected model and sufficient paid balance. https://keeprouter.com is the SDK/Claude Code base URL; do not append /v1 to it. The Messages curl example uses the full /v1/messages operation URL.
For Claude Code, keep the base URL in claude-code/settings.json and inject the token through your shell or secret manager:
export ANTHROPIC_BASE_URL=https://keeprouter.com
export ANTHROPIC_AUTH_TOKEN="$KEEPROUTER_KEY"
claudeUse a Claude model selected from the live catalog. Anthropic's gateway documentation says routing Claude Code to non-Claude models through a gateway is unsupported. A translated Messages request working once does not prove full Claude Code compatibility, including tools, streaming, or future versions. See the KeepRouter Claude Code guide for setup and verification.
Open an example request with the client, endpoint, exact model ID, and a minimal sanitized reproduction. Never post API keys, private prompts, or customer data in a public issue. The Issues list tracks real requests and fixes.
These examples are starting points, not a claim that every model, client version, or feature combination has been tested. No paid inference request is needed to review this repository.