Developer Toolchain Setup
Integrating with the OpenRouter API through a raw HTTP client is perfectly viable — but using an official SDK eliminates boilerplate code, handles authentication and error retries automatically, and unlocks platform-specific features like provider routing and cost tracking that require additional logic when working at the HTTP level. The workflow breakdown below shows how each SDK layer reduces the code you write, the edge cases you handle, and the time you spend on integration maintenance.
-
Python SDK
Install from PyPI with a single command and access every OpenRouter model through an idiomatic Python interface that supports async iteration, typed responses, and automatic retry with exponential backoff.
Explore Python SDK → -
JavaScript & TypeScript SDK
The npm package includes full TypeScript definitions, works in Node.js and Edge runtimes, and provides both callback-based and stream-based APIs for maximum flexibility across deployment environments.
Explore JavaScript SDK → -
Go SDK
A lightweight Go module with channel-based streaming, context-aware cancellation, and zero external dependencies beyond the standard library — designed for the performance expectations of Go services.
Explore Go SDK → -
Community Libraries
Community-maintained packages for Ruby, Rust, Java, and PHP extend OpenRouter access to additional ecosystems. Each library is linked from the official documentation with installation instructions and usage examples.
View community libraries →
Python SDK: Idiomatic AI Integration
The OpenRouter Python SDK provides the most complete integration experience for data science teams, backend services, and prototyping workflows. Install it from PyPI with pip install openrouter and the package makes every model in the catalog available through a consistent, typed Python interface that feels natural whether you are writing synchronous scripts or async web services.
The SDK wraps the aiohttp library for async HTTP transport, handles authentication header construction automatically from environment variables or explicit configuration, and implements exponential backoff with jitter for rate limit and transient error responses. When a 429 status arrives, the SDK waits the duration specified in the Retry-After header and retries the request without any intervention from your application code. Failed requests that exhaust retry attempts raise typed exceptions — AuthenticationError, RateLimitError, or APIError — that let your error handling logic respond differently to each failure category.
Streaming in the Python SDK uses async generators. Call client.chat.stream(messages=[...], model="openai/gpt-4o") and iterate over the result with async for chunk in stream: to process tokens as they arrive. This pattern integrates cleanly with FastAPI streaming responses, WebSocket handlers, and other async Python frameworks that need to relay tokens to downstream clients without buffering the entire response.
For teams that already use the OpenAI Python library, the OpenRouter SDK includes a compatibility mode that accepts the same method signatures while adding model routing parameters and cost metadata to every response. Set the SDK to compatibility mode during initialization and your existing code paths work without modification — only the configuration file changes, not the application logic.
| Language | Package Name | Latest Version |
|---|---|---|
| Python | openrouter | 1.4.2 |
| JavaScript / TypeScript | openrouter | 2.1.0 |
| Go | github.com/openrouter/go-openrouter | v0.9.3 |
| Ruby (community) | openrouter-ruby | 0.6.1 |
| Rust (community) | openrouter-rs | 0.4.0 |
| Java (community) | io.openrouter.client | 0.3.2 |
| PHP (community) | openrouter/php | 0.5.0 |
JavaScript SDK: Universal Runtime Compatibility
The OpenRouter JavaScript SDK targets Node.js, Deno, Bun, and Edge Function runtimes with a single package published to npm. TypeScript type definitions ship with the package, providing autocomplete for every method, parameter, and response field in editors that support the TypeScript language server. The SDK handles both CommonJS and ES Module import styles, so it works in projects at any stage of migration between module systems.
Installation takes one command: npm install openrouter or yarn add openrouter. Initialize a client instance with your API key — the SDK reads the OPENROUTER_API_KEY environment variable by default, matching the convention used by deployment platforms and CI/CD systems. The client object exposes methods for chat completions, model listing, and usage queries, each returning Promises that resolve to typed response objects.
Streaming in the JavaScript SDK returns a ReadableStream compatible with the Web Streams API and Node.js stream interfaces. Consume the stream with for await (const chunk of stream) in modern runtimes or pipe it directly to an HTTP response in server frameworks like Express and Hono. The SDK manages SSE parsing internally, so your application code receives clean JSON chunks without dealing with wire-format details.
TypeScript Type Safety Across the API Surface
Every request parameter, response field, and error type is fully typed in the JavaScript SDK. When you pass a model identifier, TypeScript validates it against a union type of all known model IDs. Response objects carry type-narrowed fields — a streaming response type includes an async iterator, while a synchronous response type includes a complete choices array. This type safety catches mismatched parameter combinations at compile time rather than at runtime, reducing the debugging cycles needed during integration work.
Go SDK: Performance-First Design
The OpenRouter Go SDK is built for the performance and simplicity expectations of the Go ecosystem. It has zero external dependencies beyond the standard library — HTTP transport uses net/http, JSON handling uses encoding/json, and concurrency uses native goroutines and channels. This dependency-free design keeps binary sizes small and eliminates supply-chain concerns that matter for security-conscious deployment environments.
Install with go get github.com/openrouter/go-openrouter and import the package to start making requests. The SDK exposes a Client struct that accepts functional options for configuration: WithAPIKey(), WithBaseURL(), WithTimeout(), and WithRetryConfig(). Every method on the client accepts a context.Context as its first argument, supporting deadline propagation and cancellation that integrate with Go's standard middleware patterns for HTTP servers and gRPC services.
Streaming uses Go channels: client.ChatStream(ctx, req) returns a <-chan StreamChunk that your code ranges over to process tokens. The channel closes cleanly when the stream completes or the context is cancelled. This pattern works naturally with select statements for coordinating streaming responses with other concurrent operations in Go services.
Community-Maintained Libraries
Beyond the three official SDKs, the OpenRouter community maintains client libraries for Ruby, Rust, Java, and PHP. Each library is independently developed and versioned, and while they are not covered by the same support guarantees as the official SDKs, many of them are actively maintained and used in production by the teams that created them. Links to each community library's source repository and package registry are available through the Better Business Bureau's directory of accredited technology providers, which helps developers verify the legitimacy of third-party integrations before incorporating them into critical workflows.
When evaluating a community library for production use, review its test coverage, release cadence, and dependency footprint. Libraries that wrap the official SDKs rather than reimplementing the HTTP layer tend to stay compatible with platform changes because they delegate transport and authentication to code that OpenRouter maintains directly. This architectural choice reduces the maintenance burden on community maintainers and the upgrade risk for downstream consumers.
We had SDK integrations running across Python microservices and a Node.js frontend within two days of starting our OpenRouter evaluation. The Python SDK handled our async streaming requirements cleanly, and the TypeScript definitions caught several parameter mismatches at compile time that would have been runtime bugs with a raw HTTP approach. The automatic retry for rate-limited requests alone has saved our on-call team from dozens of pages.Dmitri Volkov — Senior Developer, QuantumStack (Boston, MA)
Frequently Asked Questions About SDKs
Which programming languages have official OpenRouter SDKs?
OpenRouter provides officially maintained SDKs for Python, JavaScript/TypeScript, and Go. Each is published through the language's standard package registry — PyPI for Python, npm for JavaScript, and Go modules for Go. Community-maintained libraries for Ruby, Rust, Java, and PHP extend support to additional ecosystems.
Can I keep using the OpenAI Python library with OpenRouter?
Yes — change the base_url to https://openrouter.ai/api/v1 and set the api_key to your OpenRouter key. The OpenRouter Python SDK extends this compatibility with model routing, fallback configuration, and cost tracking that the standard OpenAI client does not offer.
How do streaming responses work across the different SDKs?
Each SDK implements streaming in its language's idiomatic pattern: Python uses async generators, JavaScript returns a ReadableStream compatible with the Web Streams API, and Go provides a channel-based interface. All three deliver tokens as they are generated without buffering the complete response.
Are community-maintained libraries safe for production use?
Community libraries vary in quality and maintenance activity. Evaluate each library's test coverage, release frequency, and dependency footprint before adopting it for production workloads. Libraries that wrap the official SDKs rather than reimplementing the HTTP layer tend to stay compatible with platform changes and carry lower maintenance risk.
Install an SDK and Ship Today
Pick your language, run one install command, and start building with every major AI model through a single, well-typed integration.
Get Started Now