EN ▾
Get API key

OpenRouter API Integration: Connect LangChain, Cursor, SDKs

If your code already talks to an OpenAI-style endpoint, an openrouter api integration is mostly a matter of swapping a base URL and a key. This page shows the same swap for this independent API, which is not OpenRouter, in LangChain, Cursor, the OpenAI SDKs and plain HTTP.

Updated

Cable linking a terminal to a row of tool blocks, showing an API endpoint integration

No card needed. After sign-up, claim $0.50 of free test credit with one click (once per person).

Get API key

Key points

What changes when you point a client at this API

OpenRouter, this service and many others all copy the same wire format: POST /v1/chat/completions with a JSON body of model and messages, authenticated by a bearer token. Because the format is shared, most clients need exactly three values changed.

  1. Base URL: https://api.openrouteruncensored.com/v1
  2. API key: the key from your account, sent as Authorization: Bearer <key>
  3. Model ID: uncensored

That last one is where people trip. This service runs one open-weight model, so there is no list of vendor-prefixed names such as you might use with a router. If your config has a model string from somewhere else, replace it with uncensored. You can confirm what the server exposes with GET /v1/models.

Two other differences are worth knowing before you start. First, this is not a router: there is no fallback to other vendors and no provider-selection parameters, so any routing options in your code will have no effect. Second, it handles text only. Image, audio and video generation, embeddings and fine-tuning are not offered, so a pipeline that needs embeddings must get them elsewhere.

The quickstart has a shorter version of this checklist if you only need the basics.

Test the connection with curl first

Before touching a framework, prove the key and URL work with one request. If this fails, no library will succeed, and the error is easier to read here.

curl https://api.openrouteruncensored.com/v1/chat/completions \
  -H "Authorization: Bearer YOUR_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "uncensored",
    "messages": [{"role": "user", "content": "Reply with the single word ready."}],
    "max_tokens": 10
  }'

A 200 response with a choices array means you are connected. A 401 points to a missing or mistyped key. A 429 with the code rate_limited means too many requests per minute, and the code concurrency means too many at once. The response headers include X-Request-Id, which is the identifier to quote if you contact support, and X-Balance-USD, which shows what is left in your account.

Setting max_tokens is optional. Without it, the completion can use whatever remains of the 100,000-token window, so for tests a small cap keeps the bill and the wait short.

Python and Node with the OpenAI SDK

The official OpenAI libraries accept a base URL in the constructor. In Python:

from openai import OpenAI

client = OpenAI(
    base_url="https://api.openrouteruncensored.com/v1",
    api_key="YOUR_KEY",
)

stream = client.chat.completions.create(
    model="uncensored",
    messages=[
        {"role": "system", "content": "You are a concise assistant."},
        {"role": "user", "content": "Give me three names for a fantasy tavern."},
    ],
    temperature=0.9,
    stream=True,
)

for chunk in stream:
    if chunk.choices and chunk.choices[0].delta.content:
        print(chunk.choices[0].delta.content, end="", flush=True)

In Node:

import OpenAI from "openai";

const client = new OpenAI({
  baseURL: "https://api.openrouteruncensored.com/v1",
  apiKey: process.env.API_KEY,
});

const res = await client.chat.completions.create({
  model: "uncensored",
  messages: [{ role: "user", content: "Write a two-line limerick about caching." }],
});

console.log(res.choices[0].message.content);

If you would rather not edit code at all, the Python and Node SDKs also read the OPENAI_BASE_URL and OPENAI_API_KEY environment variables. Setting those two in your shell or deployment config redirects an existing script without a single code change, which makes it easy to A/B the endpoint against whatever you use today.

Parameters such as temperature, top_p, stop, seed and the frequency and presence penalties are passed through to the model. Streaming uses server-sent events and reports usage at the end of the stream.

LangChain

LangChain's OpenAI chat wrapper takes the same overrides. With the Python package langchain-openai:

from langchain_openai import ChatOpenAI
from langchain_core.prompts import ChatPromptTemplate

llm = ChatOpenAI(
    model="uncensored",
    base_url="https://api.openrouteruncensored.com/v1",
    api_key="YOUR_KEY",
    temperature=0.7,
)

prompt = ChatPromptTemplate.from_messages([
    ("system", "You write short product descriptions."),
    ("human", "{item}"),
])

chain = prompt | llm
print(chain.invoke({"item": "a stainless steel water bottle"}).content)

A few LangChain-specific notes. The parameter names have shifted between versions, with older releases using openai_api_base and openai_api_key, so if one spelling is rejected, try the other. Use the chat class, not the legacy completions class, because only the chat completions method is offered here. Token streaming with .stream() works the usual way.

Tool calling in an agent

Tool calling follows the OpenAI schema: you pass tools and optionally tool_choice, the model returns tool_calls, and you send results back as messages with role: "tool". In streaming mode the tool_calls arrive in pieces that your client must assemble, which LangChain and the OpenAI SDKs do for you. If you write your own loop, concatenate the argument fragments by index before parsing the JSON.

For structured output, JSON mode is available with response_format: {"type": "json_object"}. Tell the model in the prompt that you expect JSON, and validate the result in your code regardless, as you would with any model.

Cursor and other editor tools

Cursor, like several editors and chat front-ends, lets you supply your own OpenAI-compatible endpoint. The usual path is the models section of the settings, where you enter an API key, override the OpenAI base URL, and add a custom model name. The exact menu labels change between releases, so check the editor's current documentation if you cannot find them.

The values to enter are the same three as before:

Be realistic about what to expect. Editors often ship features that depend on the vendor's own models, such as special completion or apply models, and those will not route through a custom endpoint. Chat and edit panels that use the standard chat completions call are the likeliest to work. This is a general-purpose chat model with a 100,000-token window, so do not expect specialized code-completion behavior.

The same pattern covers other tools that expose an OpenAI-compatible option, such as chat front-ends and roleplay clients like SillyTavern, which let you add a custom endpoint. Enter the base URL and key, pick or type uncensored as the model, and send a test message.

Limits, retries and common errors

Integration problems after the first success are almost always about limits. A full key allows 8 concurrent requests and 300 requests per minute. A trial key allows 2 and 60. The maximum request body is 8 MB.

SymptomLikely causeFix
429, code concurrencyMore requests in flight than your slot countCap your worker pool at 8 (2 on trial)
429, code rate_limitedMore than 300 requests per minuteAdd a token bucket or a short sleep
429 with Retry-After: 5Temporary overloadWait the 5 seconds and retry
Streams stall your batchA stream holds its slot until it endsLower parallelism or read streams to completion
Model not foundA model string from another providerUse uncensored

A small retry wrapper handles most of these:

import time
from openai import OpenAI, RateLimitError

client = OpenAI(base_url="https://api.openrouteruncensored.com/v1", api_key="YOUR_KEY")

def ask(prompt, tries=4):
    for attempt in range(tries):
        try:
            r = client.chat.completions.create(
                model="uncensored",
                messages=[{"role": "user", "content": prompt}],
            )
            return r.choices[0].message.content
        except RateLimitError:
            time.sleep(5 * (attempt + 1))
    raise RuntimeError("still rate limited")

Failed or refused requests are not charged, so a retry loop does not double your bill. Pricing is $0.15 per 1M input tokens and $0.50 per 1M output tokens; see the pricing page for top-up details.

Getting a key and testing for free

Sign up with Google, or with email and password, then open the key page. A new account can claim $0.50 of trial credit with one click: no card, one per person, valid for 7 days. That is enough to run the snippets above and see how your own prompts behave. When you move to production, add credit from $20 and use a full key for the higher limits. The API key page walks through both steps.

The service is for lawful adult use, and it does not produce sexual content involving minors under any configuration. Prompts are not used for training.

Questions and answers

Is this API the same as OpenRouter?

No. It is an independent service with one open-weight model, not a router across vendors. Only the request format is shared.

What model name do I use in my config?

Use uncensored as the model ID. You can list it with GET /v1/models.

Does LangChain work with this endpoint?

Yes, through ChatOpenAI with a custom base URL and key. Tool calling and streaming follow the OpenAI format.

Can I use embeddings or image generation through it?

No. The API covers text chat completions only, with no embeddings, image, audio or video endpoints.

What are the rate limits?

A full key allows 8 concurrent requests and 300 requests per minute. A trial key allows 2 concurrent and 60 per minute.

Your key is one form away

Create an account, copy the key, change the base URL. That is the whole setup.

Get API key