---
title: "LangChain OpenAI compatible API for uncensored builds"
canonical: https://unrestrictable.ai/guides/langchain
generated: 2026-11-16T02:57:38.678Z
source: https://unrestrictable.ai/guides/langchain
base_url: https://api.unrestrictable.ai/v1
---

# Run LangChain and LangGraph agents on an uncensored model

Point ChatOpenAI at our base URL in Python or JavaScript, pick an uncensored id, hand the instance to create_agent. Token counts, agent turn prices, the errors.

Steps checked November 2, 2026 · prices as of November 16, 2026

Two constructor arguments, a base URL and a key, move `ChatOpenAI` off OpenAI and onto an uncensored build, with your existing chains and agents untouched. Pick an id on the [models page](https://unrestrictable.ai/models), build the instance in Python or JavaScript, and `create_agent` runs its tool loop against it. Prefer to skip the install? The same models answer in the browser at [/chat](https://unrestrictable.ai/chat).

## What you need

- Python 3 with pip, or Node 22 or newer with npm.
- A key from the [console](https://app.unrestrictable.ai/console). It begins with `sk-unr-` and draws on a prepaid balance.
- A model id, copied as the [models page](https://unrestrictable.ai/models) prints it. The snippets use glm-5.3-uncensored, glm-5.3-flash-uncensored, deepseek-v4.1-flash-abliterated, the three ids LangChain users send most often here.

No settings panel is involved. `ChatOpenAI`, from `langchain-openai` in Python and `@langchain/openai` in JavaScript, takes the endpoint and the key as constructor arguments: `base_url` plus `api_key` on the Python side, `apiKey` plus `configuration.baseURL` on the JavaScript side. `init_chat_model` and `initChatModel` accept the same pair next to `model_provider="openai"`. Agents built with `create_agent` (`createAgent` in JavaScript) take that instance, so the endpoint is set in one place. LangGraph’s `create_react_agent` is the older name for the same thing.

To try a build before writing a line, open [/chat](https://unrestrictable.ai/chat) or message the [Telegram bot](https://unrestrictable.ai/telegram); both give a few free replies a day without an account.

## First reply

1. Install the model package. Add the agent package too if you want a tool loop later:

```bash
pip install -U langchain langchain-openai
```

```bash
npm install langchain @langchain/openai @langchain/core zod
```

1. Export the key into the shell. The scripts below read the variable, so the key never sits in a file you might commit.

```bash
export UNRESTRICTABLE_API_KEY="sk-unr-live-…"
```

1. Python: build `ChatOpenAI` from the id, the key and our base URL. `invoke` gives back an `AIMessage`; its `usage_metadata` is the token count you paid for. `stream` hands over chunks while the model is still writing.

```
import os
from langchain_openai import ChatOpenAI

model = ChatOpenAI(
    model="glm-5.3-uncensored",
    api_key=os.environ["UNRESTRICTABLE_API_KEY"],
    base_url="https://api.unrestrictable.ai/v1",
    max_tokens=1024,
    stream_usage=True,  # usage on streamed replies too; LangChain switches it off when base_url is given
)

response = model.invoke("Explain, in three sentences, when a bloom filter beats a hash set.")
print(response.content)
print(response.usage_metadata)  # {'input_tokens': …, 'output_tokens': …, 'total_tokens': …}

for chunk in model.stream("List the POSIX signals a daemon should handle."):
    print(chunk.content, end="", flush=True)
```

When the model id comes from a config file, `init_chat_model` produces the identical object from a provider name:

```
from langchain.chat_models import init_chat_model

model = init_chat_model(
    model="glm-5.3-flash-uncensored",
    model_provider="openai",
    base_url="https://api.unrestrictable.ai/v1",
    api_key=os.environ["UNRESTRICTABLE_API_KEY"],
)
```

Both values can also live in the environment. LangChain reads `OPENAI_API_KEY` when `api_key` is missing, and `OPENAI_API_BASE`, then `OPENAI_BASE_URL`, when `base_url` is missing. Export the two below and a bare `ChatOpenAI(model="…")` hits this API. If the same process also calls OpenAI, keep the arguments explicit; otherwise both clients end up on one base URL.

```bash
export OPENAI_API_KEY="sk-unr-live-…"
export OPENAI_BASE_URL="https://api.unrestrictable.ai/v1"
```

1. JavaScript: identical values, except the URL sits inside `configuration.baseURL`. That `configuration` object goes straight to the OpenAI SDK client, which is where any other client option belongs as well.

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

const model = new ChatOpenAI({
  model: "glm-5.3-uncensored",
  apiKey: process.env.UNRESTRICTABLE_API_KEY,
  configuration: { baseURL: "https://api.unrestrictable.ai/v1" },
  maxTokens: 1024,
});

const response = await model.invoke("Explain, in three sentences, when a bloom filter beats a hash set.");
console.log(response.content);
console.log(response.usage_metadata); // { input_tokens, output_tokens, total_tokens }

const stream = await model.stream("List the POSIX signals a daemon should handle.");
for await (const chunk of stream) process.stdout.write(String(chunk.content));
```

## An agent on the same instance

Give the model object to `create_agent` together with your tools. Each pass sends the conversation, executes whichever tool the model requested, adds the result to the thread and asks again, until a plain text reply comes back. Only a build whose model page lists tool calls can drive this; the table further down marks them.

```
import os
from langchain.agents import create_agent
from langchain.tools import tool
from langchain_openai import ChatOpenAI

@tool
def read_file(path: str) -> str:
    """Read a UTF-8 text file and return its contents."""
    with open(path, encoding="utf-8") as f:
        return f.read()

model = ChatOpenAI(
    model="glm-5.3-uncensored",
    api_key=os.environ["UNRESTRICTABLE_API_KEY"],
    base_url="https://api.unrestrictable.ai/v1",
)

agent = create_agent(
    model=model,
    tools=[read_file],
    system_prompt="You review Python code. Read a file before you comment on it.",
)

result = agent.invoke({"messages": [{"role": "user", "content": "Review ./app.py for bugs."}]})
print(result["messages"][-1].content)
```

Existing LangGraph code on `create_react_agent` still runs; `model` and `tools` are unchanged and the system prompt goes in as `prompt`. The deprecation message points to the import shown above. In JavaScript the agent looks the same:

```
import { readFile } from "node:fs/promises";
import { ChatOpenAI } from "@langchain/openai";
import { createAgent, tool } from "langchain";
import * as z from "zod";

const readTextFile = tool(async ({ path }) => readFile(path, "utf8"), {
  name: "read_file",
  description: "Read a UTF-8 text file and return its contents.",
  schema: z.object({ path: z.string() }),
});

const model = new ChatOpenAI({
  model: "glm-5.3-uncensored",
  apiKey: process.env.UNRESTRICTABLE_API_KEY,
  configuration: { baseURL: "https://api.unrestrictable.ai/v1" },
});

const agent = createAgent({
  model,
  tools: [readTextFile],
  systemPrompt: "You review TypeScript code. Read a file before you comment on it.",
});

const result = await agent.invoke({ messages: [{ role: "user", content: "Review ./app.ts for bugs." }] });
console.log(result.messages.at(-1)?.content);
```

## Each argument

- model: glm-5.3-uncensored the id exactly as the models page writes it; it becomes the model field of every request
- api_key / apiKey: os.environ["UNRESTRICTABLE_API_KEY"] the full sk-unr- key, sent as Authorization: Bearer; if omitted, Python reads OPENAI_API_KEY
- base_url / configuration.baseURL: https://api.unrestrictable.ai/v1 the destination; the client adds /chat/completions after it, so keep the trailing /v1
- max_tokens / maxTokens: 1024 ceiling on output tokens per reply; each build’s maximum is on its model page
- stream_usage: True Python only: requests the usage chunk on streams. LangChain disables it once base_url is set, and this API does answer it, so switch it back on. JavaScript sends it by default (streamUsage)
- streaming: False when true, invoke streams under the hood and joins the chunks; stream() streams regardless
- temperature, timeout, max_retries: optional sampling temperature, how long a request may take, and how often the client retries a failed one
- tools / system_prompt: create_agent the functions the agent is allowed to call, and the message placed first in every call; in createAgent the field is systemPrompt

## Which build

Every build on the models page answers the OpenAI-format requests that `ChatOpenAI` sends, so `invoke` and `stream` accept any id. Tool calls are the dividing line: the agent loop depends on them, as do `bind_tools` and `with_structured_output` in its default function-calling method. Because an agent turn resends the whole conversation plus every file and tool result so far, input tokens dominate the cost, and a low input price is what makes a turn cheap.

| Model | One agent turn | Tool calls |
| --- | --- | --- |
| [GLM-5.3 Uncensored](https://unrestrictable.ai/models/glm-5.3-uncensored) | $0.01 | [model page](https://unrestrictable.ai/models/glm-5.3-uncensored) |
| [GLM-5.3 Flash Uncensored](https://unrestrictable.ai/models/glm-5.3-flash-uncensored) | $0.0047 | [model page](https://unrestrictable.ai/models/glm-5.3-flash-uncensored) |
| [DeepSeek V4.1 Flash Abliterated](https://unrestrictable.ai/models/deepseek-v4.1-flash-abliterated) | $0.04 | [model page](https://unrestrictable.ai/models/deepseek-v4.1-flash-abliterated) |
| [DeepSeek V4 Pro Uncensored](https://unrestrictable.ai/models/deepseek-v4-pro-uncensored) | $0.04 | [model page](https://unrestrictable.ai/models/deepseek-v4-pro-uncensored) |
| [GLM-5.3 Abliterated](https://unrestrictable.ai/models/glm-5.3-abliterated) | $0.09 | [model page](https://unrestrictable.ai/models/glm-5.3-abliterated) |
| [GLM-5.3 Flash Code Uncensored](https://unrestrictable.ai/models/glm-5.3-flash-code-uncensored) | $0.25 | [model page](https://unrestrictable.ai/models/glm-5.3-flash-code-uncensored) |

A turn of 40,000 input and 1,200 output tokens, priced from the catalog on 2026-11-16. The tool-call column repeats what the catalog publishes; a blank cell means the model page has the answer.

| Model | Build | Input $/M | Output $/M |
| --- | --- | --- | --- |
| [GLM-5.3 Uncensored](https://unrestrictable.ai/models/glm-5.3-uncensored) glm-5.3-uncensored | Uncensored | $0.282 | $0.846 |
| [GLM-5.3 Flash Uncensored](https://unrestrictable.ai/models/glm-5.3-flash-uncensored) glm-5.3-flash-uncensored | Uncensored | $0.1053 | $0.3685 |
| [DeepSeek V4.1 Flash Abliterated](https://unrestrictable.ai/models/deepseek-v4.1-flash-abliterated) deepseek-v4.1-flash-abliterated | Abliterated | $0.8488 | $1.6975 |
| [DeepSeek V4 Pro Uncensored](https://unrestrictable.ai/models/deepseek-v4-pro-uncensored) deepseek-v4-pro-uncensored | Uncensored | $0.97 | $1.94 |
| [GLM-5.3 Abliterated](https://unrestrictable.ai/models/glm-5.3-abliterated) glm-5.3-abliterated | Abliterated | $2.1825 | $4.365 |
| [GLM-5.3 Flash Code Uncensored](https://unrestrictable.ai/models/glm-5.3-flash-code-uncensored) glm-5.3-flash-code-uncensored | Uncensored | $6.00 | $6.00 |

Prices per million tokens, read from the live catalog on 2026-11-16.

Building a coding agent? [The uncensored coding AI guide](https://unrestrictable.ai/guides/uncensored-coding-ai) puts the code builds side by side and prices a whole working day on each. The ids here also drop into [Cursor](https://unrestrictable.ai/guides/cursor), [OpenCode](https://unrestrictable.ai/guides/opencode) and, behind a router, [Claude Code](https://unrestrictable.ai/guides/claude-code).

## Prove it works

Ask the API which models the key may call. The id you chose for `model` has to appear in the list:

```bash
curl https://api.unrestrictable.ai/v1/models -H "Authorization: Bearer sk-unr-live-…"
```

Next, post one request shaped the way `ChatOpenAI` posts it. With `-i` you see the response headers: one carries the request id, and on a non-streamed reply another carries the charge in USD.

```bash
curl -i https://api.unrestrictable.ai/v1/chat/completions \
  -H "Authorization: Bearer sk-unr-live-…" \
  -H "Content-Type: application/json" \
  -d '{"model": "glm-5.3-uncensored", "messages": [{"role": "user", "content": "Reply with the single word ok."}]}'
```

Now run the Python or JavaScript file. The `usage_metadata` on the reply is the input and output count the request was billed on, and the console’s usage page shows the same request with its charge. For streams the count rides on the final chunk, and in Python only when `stream_usage=True`.

## When it fails

- `401 invalid_api_key`: a mistyped or revoked key, or `UNRESTRICTABLE_API_KEY` is not exported in the shell running the script. Export it once more, or make a fresh copy from the console. If the 401 body mentions OpenAI, `base_url` never took effect and the key went to OpenAI instead.
- `404 model_not_found`: nothing on the models page matches the `model` value. Compare the spelling. `404 route_not_found`: the request landed on a path we do not serve. Either the base URL lost its `/v1`, so the client posted `/chat/completions` at the host root, or it went to `/responses`, which happens when `use_responses_api=True` is set or when a Responses-only option (`reasoning`, a built-in tool) is used. We serve `/v1/chat/completions`; drop those options.
- `402 insufficient_balance`: the balance cannot cover this call; add credit in the console. `402 monthly_limit_reached`: the key has spent the monthly cap you set for it.
- `403 scope_denied`: the key is scoped to specific models, and this id is outside that scope.
- `429 rate_limited`: the key is over its rate limit. A `retry-after` header says how long to wait; with `max_retries` set, the client waits and retries by itself.
- `usage_metadata` comes back `None` from a Python stream: a present `base_url` makes LangChain default `stream_usage` to off. Give `stream_usage=True` to the constructor, or to the `stream` call.
- The agent only writes prose and never picks a tool, or the `tools` field is rejected: this build has no tool calls. Move to one whose model page lists them. `with_structured_output` on its default method has the same requirement; `method="json_schema"` instead needs a build that accepts `response_format`.
- The reply cuts off and `finish_reason` reads `length`: `max_tokens` is below what the answer needed. Raise it, up to the limit on the model page.

## Questions

### Is LangChain tied to OpenAI’s servers?

No. ChatOpenAI speaks the OpenAI wire format, and it only reaches OpenAI when no base URL is given. Set base_url (Python) or configuration.baseURL (JavaScript) to this API and pass a console key, and the same class, chains and agents run on an uncensored build without an OpenAI account.

### Can I use the OpenAI Responses API through LangChain here?

Not with this API. ChatOpenAI moves to Responses once use_responses_api=True is set, or once a Responses-only feature (reasoning, a built-in tool) is in play. We serve Chat Completions, which is also ChatOpenAI’s default, so leave those off; invoke, stream, bind_tools and create_agent all work on Chat Completions.

### Which uncensored models can LangChain call on this API?

All of them. One key reaches every id on the models page over /v1/chat/completions in OpenAI format, so each can be the model argument, spelled as the page spells it. For agents, bind_tools or default structured output, pick a build with tool calls on its model page; the table above marks them. See the models page.

### What does OpenAI compatible API mean?

An endpoint that takes the OpenAI request body at /v1/chat/completions and returns the OpenAI response body, so a client built for OpenAI only needs a new base URL and key. This API is one. ChatOpenAI is such a client, and its usage_metadata reports the tokens each request was billed on, charged per token against your prepaid balance.

Every model above is on the [uncensored model list](https://unrestrictable.ai/models) with its live price per million tokens. [Per-token pricing](https://unrestrictable.ai/pricing) sets the whole catalog side by side, and the [family directory](https://unrestrictable.ai/uncensored) groups the builds by base model.

[Get a key](https://app.unrestrictable.ai/console) Prepaid from $10, no subscription.

## New models and price changes, once a month.

New uncensored builds with their prices, price moves, and what the daily model check found.
