OpenRouter api Documentation
Connect your application to our uncensored LLM using the standard OpenAI-compatible interface. This guide covers authentication, request formats, and streaming for rapid integration.
Quickstart: Connect with Python
Start by installing the official SDK and pointing it at our base URL.
Our API behaves like the standard OpenAI interface but routes to a single uncensored model. This approach eliminates proxy complexity while keeping your code portable.
- Install the library via pip.
- Set your API key in the environment.
- Define the base URL for our endpoint.
from openai import OpenAI
client = OpenAI(base_url="https://api.apiopenrouter.com/v1", api_key="YOUR_KEY")
resp = client.chat.completions.create(
model="uncensored",
messages=[{"role": "user", "content": "Summarise this thread without softening it."}],
)
print(resp.choices[0].message.content)Replace the placeholder key with your own credentials. You can send simple prompts or complex structured data.
Authentication and Keys
Generate a key on the dashboard and pass it in the Authorization header.
Each account supports one active key at a time. When you create a new key, the old one stops working immediately. This simplifies security management without requiring complex rotation logic.
curl https://api.apiopenrouter.com/v1/chat/completions \
-H "Authorization: Bearer $API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "uncensored",
"messages": [{"role": "user", "content": "List the top 5 dependencies for a Go web server"}]
}'The request above uses the Bearer scheme. Ensure your key starts with sk- and contains no extra whitespace.
Chat Completions Endpoint
Send messages to the /v1/chat/completions endpoint using standard JSON.
The model accepts user and assistant roles. You can configure temperature, top-p, and stop sequences to control output style. Responses return token usage in the final chunk if streaming is enabled.
import OpenAI from "openai";
const client = new OpenAI({ baseURL: "https://api.apiopenrouter.com/v1", apiKey: process.env.API_KEY });
const resp = await client.chat.completions.create({
model: "uncensored",
messages: [{ role: "user", content: "Draft a villain monologue for my game." }],
});
console.log(resp.choices[0].message.content);Set max_tokens to control output length. If omitted, the default is 2,048 tokens. The model supports up to 16,000 tokens per request.
Streaming Responses
Enable streaming by setting stream: true in your request body.
Token usage details appear only in the last chunk of the stream. This allows real-time UI updates while preserving accurate billing data. Errors during streaming still report usage for charged tokens.
stream = client.chat.completions.create(
model="uncensored",
messages=[{"role": "user", "content": "Tell the story in second person."}],
stream=True,
)
for chunk in stream:
if chunk.choices and chunk.choices[0].delta.content:
print(chunk.choices[0].delta.content, end="", flush=True)Handle partial responses gracefully. The stream closes normally when the model finishes generation or hits the context limit.
Function Calling & JSON Mode
Use response_format: {type: "json_object"} for strict JSON outputs.
Define tools in the tools array and set tool_choice to enforce function calls. The model returns structured data suitable for programmatic processing. This works reliably with our uncensored weights.
curl https://api.apiopenrouter.com/v1/chat/completions \
-H "Authorization: Bearer $API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "uncensored",
"messages": [{"role": "user", "content": "List the top 5 dependencies for a Go web server"}]
}'Combine function calling with streaming for interactive experiences. Validate the JSON output before passing it to your application logic.
Limits and Quotas
Monitor your usage against the per-key limits to avoid interruptions.
Each key allows 300 requests per minute and 8 concurrent requests. The request body size limit is 8 MB. If you exceed these limits, the API returns a 429 status code. Authentication errors return 401, and insufficient credit returns 402.
curl https://api.apiopenrouter.com/v1/chat/completions \
-H "Authorization: Bearer $API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "uncensored",
"messages": [{"role": "user", "content": "List the top 5 dependencies for a Go web server"}]
}'The context window is 100,000 tokens total. Errors do not consume credit. Refusals for minor content violations also remain free.
Common questions
How does the openrouter API differ from standard OpenAI?
Our API uses a single uncensored model optimized for lawful adult and creative content without refusals. It maintains the same request and response structure as OpenAI, allowing you to swap endpoints without changing your code.
What happens if I run out of credits?
Requests fail with a 402 error when your prepaid balance is zero. Credits never expire, so you can top up via crypto at any time. Errors and refusals do not consume your balance.
Can I use multiple keys for different projects?
Each account supports one active key. Creating a new key automatically invalidates the previous one. You can generate a new key instantly from the dashboard without losing your billing history.
Retrieve your API key
Sign up, copy the token, and update your base URL. That is the entire configuration.