Rate limits and retries that behave
Handle temporary failures without repeating a charge or losing the request context.
Read the guidePython, JavaScript, or Rust? Use practical code that connects one application to GPT, Claude, and other models through a single API.
Build the first working call today.
from openai import OpenAI
client = OpenAI(
base_url="https://openrouter.ai/api/v1",
api_key="YOUR_OPENROUTER_KEY"
)
response = client.chat.completions.create(
model="anthropic/claude-3.5-sonnet",
messages=[{"role": "user",
"content": "Summarise this issue."}]
)
# Change one string to test another model.
print(response.choices[0].message.content)
Each guide focuses on a working integration detail, with logging, error handling, and model choices included.
Handle temporary failures without repeating a charge or losing the request context.
Read the guideKeep conversation history clean while routing short prompts and long context to the right model.
Read the guideSend partial responses to the interface while keeping a Rust service responsive under load.
Read the guideChange the base URL, preserve your message format, then add model selection with minimal refactoring.
Read the guidePlace the provider call behind a small server route and return only the data your client needs.
Read the guideSet a clear retry boundary and move to a second model when the first response fails.
Read the guideStart with the client your team can test quickly. Move deeper when performance or control calls for it.
| Capability | Python Recommended start | JavaScript | Rust |
|---|---|---|---|
| First request | Very easy | Easy | Moderate |
| Throughput | High | High | Very high |
| Streaming support | Built in | Built in | Built in |
| Community libraries | Wide range | Wide range | Focused set |
| Best first project | Scripts and APIs | Web applications | Low-latency services |
These small examples show the decisions that change when one codebase speaks to several models.
# One client, one model string.
response = client.chat.completions.create(
model="openai/gpt-4o-mini",
messages=[{"role": "user", "content": prompt}]
)
print(response.choices[0].message.content)
One email each week with an OpenRouter integration deep-dive and working code.
Good examples remove hesitation at the exact point a build gets stuck.
"The Python retry example saved our launch. We went live with clear logs, a sensible fallback, and confidence in the first production call."
Choose the next guide around your product decision, then return when you are ready for another implementation detail.
Keep intent detection, model choice, and conversation state in separate layers.
Compare model responses with repeatable prompts, useful events, and clean outcome data.
See how OpenRouter-Blog explains model access, routing choices, and practical adoption.