EN ▾
Get API key

Uncensored API for developers

per 1M input tokens
$0.15
Output tokens / 1M
$0.50
token context
100,000
trial credit
$0.50
requests per minute
300
unrestrictedsearch.com

LangChain base_url Setup for an OpenAI-Compatible API

To point LangChain at a different server, pass base_url to ChatOpenAI along with an API key and the model name. This page has the exact code for our endpoint, plus streaming, tools, structured output and the errors you are most likely to see.

Chain links routed through a switch plate to a server tower, showing LangChain redirected to another base URL

Key points

  1. Use ChatOpenAI from langchain-openai with base_url set to https://api.unrestrictedsearch.com/v1 and model set to uncensored.
  2. The same settings work through environment variables, and in Node through the configuration option.
  3. Streaming, bind_tools and JSON-mode structured output all pass through to the API.
  4. Cap batch concurrency below your key limit: 8 for a full key, 2 for a trial key.

The minimal setup

The langchain base_url setting lives on the ChatOpenAI class from the langchain-openai package. Give it the base URL of any OpenAI-compatible server and LangChain sends its chat requests there instead of to OpenAI. For our API the values are:

  • Base URL: https://api.unrestrictedsearch.com/v1
  • Model: uncensored
  • Key: your API key, sent as a Bearer token
pip install -U langchain-openai langchain-core
from langchain_openai import ChatOpenAI

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

reply = llm.invoke("Give me two plot twists for a heist story.")
print(reply.content)

That is the whole change. Chains, prompts, output parsers and memory classes sit above the model object and do not care where the HTTP request goes. If you do not have a key yet, the key page explains sign-up and the one-click trial credit.

Setting the URL through environment variables

Hard-coding a key in source is a habit worth skipping. The underlying OpenAI client reads OPENAI_API_KEY and OPENAI_BASE_URL from the environment, and ChatOpenAI also accepts the older name OPENAI_API_BASE. Set them in your shell or a .env file and the constructor shrinks.

export OPENAI_API_KEY="YOUR_API_KEY"
export OPENAI_BASE_URL="https://api.unrestrictedsearch.com/v1"
from langchain_openai import ChatOpenAI

llm = ChatOpenAI(model="uncensored")
print(llm.invoke("Reply with the single word: ready").content)

A warning that saves debugging time: if the project already has OPENAI_API_KEY set for the real OpenAI service, an environment variable can silently win over what you intended. Passing base_url and api_key explicitly in code makes it obvious which server a given object talks to. That matters when one program uses two models from two providers.

Node and TypeScript

In JavaScript the package is @langchain/openai, and the URL goes inside a configuration object.

import { ChatOpenAI } from "@langchain/openai";

const llm = new ChatOpenAI({
  model: "uncensored",
  apiKey: process.env.API_KEY,
  configuration: { baseURL: "https://api.unrestrictedsearch.com/v1" },
  temperature: 0.7,
});

const reply = await llm.invoke("Name three moods for a noir soundtrack.");
console.log(reply.content);

Streaming

Streaming works the same as with any OpenAI-compatible backend. The server sends server-sent events when stream: true is set, and LangChain turns them into message chunks. Token usage is sent at the end of the stream.

from langchain_openai import ChatOpenAI

llm = ChatOpenAI(
    model="uncensored",
    base_url="https://api.unrestrictedsearch.com/v1",
    api_key="YOUR_API_KEY",
)

for chunk in llm.stream("Describe a rainy harbor town in five sentences."):
    print(chunk.content, end="", flush=True)

Keep in mind that a streamed request occupies a concurrency slot until the last chunk arrives. If your code starts a stream and abandons the iterator halfway, close it cleanly, or the slot stays busy and later calls may be rejected with the concurrency error.

Tool calling and agents

The API supports tools, tool_choice and streamed tool_calls, and tool results go back as role: "tool" messages. In LangChain you attach tools with bind_tools. This example runs one tool round trip by hand so every step is visible.

from langchain_core.tools import tool
from langchain_core.messages import HumanMessage, ToolMessage
from langchain_openai import ChatOpenAI

@tool
def add(a: int, b: int) -> int:
    '''Add two integers.'''
    return a + b

llm = ChatOpenAI(
    model="uncensored",
    base_url="https://api.unrestrictedsearch.com/v1",
    api_key="YOUR_API_KEY",
    temperature=0,
)
llm_tools = llm.bind_tools([add])

messages = [HumanMessage("What is 1234 plus 8766? Use the tool.")]
ai = llm_tools.invoke(messages)
messages.append(ai)

for call in ai.tool_calls:
    result = add.invoke(call["args"])
    messages.append(ToolMessage(content=str(result), tool_call_id=call["id"]))

final = llm_tools.invoke(messages)
print(final.content)

Agent frameworks built on LangChain, such as LangGraph's prebuilt ReAct agent, run exactly this loop for you: call the model, execute the requested tools, feed the results back, repeat until the model answers in plain text. Pass them the same llm object and they use our endpoint.

Tool reliability depends on the model. An open-weight model follows tool schemas well when the descriptions are clear and the argument types are simple. Keep the tool list short, name arguments plainly, and test with temperature=0 first, then raise it only if you want more varied wording around the tool results. If a call comes back with malformed arguments, retry once before you treat it as a failure.

Structured output with JSON mode

JSON mode is available through response_format. In LangChain the clean way to use it is with_structured_output with method="json_mode", which parses the reply into your Pydantic model. Include the word JSON and the field names in the prompt, because the mode guarantees valid syntax and not your particular schema.

from pydantic import BaseModel
from langchain_openai import ChatOpenAI

class Character(BaseModel):
    name: str
    role: str
    traits: list[str]

llm = ChatOpenAI(
    model="uncensored",
    base_url="https://api.unrestrictedsearch.com/v1",
    api_key="YOUR_API_KEY",
)
structured = llm.with_structured_output(Character, method="json_mode")

out = structured.invoke(
    "Return JSON with keys name, role and traits (a list of three strings) "
    "for a retired smuggler character."
)
print(out)

If parsing fails now and then, add a one-line example of the expected JSON to the prompt, or wrap the call in a retry. This is cheaper than it sounds: failed or refused requests are not charged, and the prices are $0.15 per 1M input tokens and $0.50 per 1M output tokens. See the pricing page for top-up options.

Prompts, chains and a system message

Most real projects wrap the model in a prompt template and a parser. LangChain's expression syntax joins them with the pipe operator, and the model object is just one link. Swapping the provider means changing that one link, which is the main reason to keep the base URL in a single place such as a settings module.

from langchain_core.prompts import ChatPromptTemplate
from langchain_core.output_parsers import StrOutputParser
from langchain_openai import ChatOpenAI

llm = ChatOpenAI(
    model="uncensored",
    base_url="https://api.unrestrictedsearch.com/v1",
    api_key="YOUR_API_KEY",
    temperature=0.8,
)

prompt = ChatPromptTemplate.from_messages([
    ("system", "You are a veteran editor. Answer in plain prose, no lists."),
    ("human", "Rewrite this opening line so it hooks harder: {line}"),
])

chain = prompt | llm | StrOutputParser()
print(chain.invoke({"line": "It was a quiet night in the city."}))

The system tuple becomes a role: "system" message in the request, and the human tuple becomes role: "user". Put standing rules in the system message so they stay fixed while the human part changes between calls.

Conversation memory in LangChain is a list of messages that gets replayed with each call, because the endpoint keeps no state. That means long chats grow the input size, and with it the cost, on every turn. Trim old turns or summarise them once the history gets long. The window is 100,000 tokens in total, so a trimmed history also protects you from hitting the ceiling mid-session.

One more habit that pays off: log the X-Request-Id response header next to each failed call in your own logs. If you contact support, that ID lets them find the exact request.

Concurrency, retries and token counts

LangChain makes it easy to fan out work with batch or with parallel branches in a chain. That is where limits start to show. A full key allows 8 concurrent requests and 300 requests per minute. A trial key allows 2 concurrent and 60 per minute. Go over and the API returns HTTP 429 with the code rate_limited or concurrency. A temporary overload also returns 429 with a Retry-After: 5 header.

prompts = [f"Write a one-line tagline for product #{i}" for i in range(40)]

results = llm.batch(prompts, config={"max_concurrency": 6})
for r in results:
    print(r.content)

Setting max_concurrency to 6 on a full key leaves headroom for other traffic on the same key. Use 1 on a trial key, so a second manual test never collides with the batch. ChatOpenAI also takes a max_retries argument, and the underlying client backs off between attempts, which smooths over a brief overload.

For accounting, trust the numbers from the server. The usage_metadata attribute on a returned message holds the input and output counts reported by the API, and the X-Balance-USD response header shows the credit left. LangChain's local token estimators are built for OpenAI tokenizers, so treat them as approximate for this model. The context window is 100,000 tokens, prompt plus completion, so long retrieval chains still need a sensible chunk budget.

Troubleshooting

SymptomLikely cause and fix
404 Not FoundThe base URL is missing /v1, or it already includes /chat/completions. Use exactly https://api.unrestrictedsearch.com/v1.
401 UnauthorizedThe key is wrong, has stray whitespace, or an old OPENAI_API_KEY from the environment is overriding yours.
Requests still go to OpenAIThe class is not receiving the URL. Pass base_url directly and print llm.openai_api_base to confirm.
429 concurrencyToo many calls at once. Lower max_concurrency or close unfinished streams.
429 rate_limitedToo many per minute. Slow the loop and retry.
Embeddings call failsThis API is text chat only and offers no embeddings. Use a separate embedding service for your vector store.

The last row trips up retrieval projects. OpenAIEmbeddings in LangChain would hit the same base URL if you configure it that way, and it will fail, so give embeddings their own client and key. Everything else in the documentation applies as written, and the unrestricted API cost analysis covers where the model fits.

Questions and answers

Which URL does LangChain need for this API?

Use https://api.unrestrictedsearch.com/v1 as base_url and uncensored as the model name. The key goes in api_key and is sent as a Bearer token.

Is it base_url or openai_api_base in LangChain?

Both work on ChatOpenAI. base_url is the current name, and openai_api_base is the older alias, so existing code that uses it keeps working.

Can I use LangChain embeddings with this endpoint?

No. The API offers chat completions and a model list only, with no embeddings. Pair it with a separate embedding model for retrieval.

Does LangChain tool calling work with this model?

Yes. Tools, tool_choice and streamed tool_calls are supported, so bind_tools and agent loops run as usual. Keep tool schemas simple for the best results.

Your key is one form away

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

Get API key