AI Agents Using LangChain With an Uncensored API
AI agents using LangChain only need a chat model that speaks the OpenAI protocol, and this API does. Point ChatOpenAI at the base URL, set the model to uncensored, and you can run tool-calling agents and JSON pipelines.
Updated

Key points
- ChatOpenAI from langchain-openai works with a custom base_url and the model ID uncensored.
- Tool calling and JSON mode are supported, so ReAct-style agents and structured output both work.
- A full key allows 8 concurrent requests and 300 per minute: cap agent parallelism accordingly.
- Test tool use on your own tasks first, since open-weight models vary in how reliably they fill arguments.
Setup: connect LangChain to the endpoint
For ai agents using langchain, the model connection is the smallest part of the job. The API is OpenAI-compatible, so you use the same class you would use for any OpenAI-style provider and change two values. Install the packages first:
pip install langchain-openai langgraph langchain-core
export UNCENSORED_KEY="YOUR_KEY"
Then create the model object. This works with the base URL and the model ID this site exposes:
import os
from langchain_openai import ChatOpenAI
llm = ChatOpenAI(
base_url="https://api.uncensoredaichatbot.top/v1",
api_key=os.environ["UNCENSORED_KEY"],
model="uncensored",
temperature=0.3,
max_retries=3,
timeout=120,
)
print(llm.invoke("Reply with the single word: ready").content)
If that prints a reply, authentication, routing and the model name are all correct. The one model on this API, uncensored, is an open-weight model run by an independent provider and tuned to answer without content refusals for lawful adult use. It is not an official endpoint of any big lab, which matters for expectations: it follows instructions well enough for many agent tasks, but you should measure it on yours rather than assume parity with any particular vendor's flagship.
Get a key from the API key page. New users can claim a $0.50 trial there, which is plenty for building and debugging an agent.
A tool-calling agent in 25 lines
The API supports the standard OpenAI tool interface: tools, tool_choice, streamed tool_calls, and results returned as messages with role: "tool". LangChain hides this behind decorators. The ReAct agent in LangGraph then runs the loop: model asks for a tool, your function runs, the result goes back, the model continues.
import os
from langchain_openai import ChatOpenAI
from langchain_core.tools import tool
from langgraph.prebuilt import create_react_agent
llm = ChatOpenAI(
base_url="https://api.uncensoredaichatbot.top/v1",
api_key=os.environ["UNCENSORED_KEY"],
model="uncensored",
temperature=0,
)
@tool
def word_count(text: str) -> int:
'''Count the words in a piece of text.'''
return len(text.split())
@tool
def reading_minutes(words: int) -> float:
'''Estimate reading time in minutes for a word count (200 words per minute).'''
return round(words / 200, 1)
agent = create_react_agent(llm, [word_count, reading_minutes])
result = agent.invoke(
{"messages": [("user", "How long would it take to read this: 'the quick brown fox jumps over the lazy dog'?")]}
)
for m in result["messages"]:
print(m.type, ":", m.content)
Print every message, not only the last one. Watching the sequence of human, AI (with tool calls), tool and final AI messages is the fastest way to see where an agent goes wrong. Common failures are a tool argument with the wrong type, a model that answers from memory instead of calling the tool, and a loop that repeats the same call.
Making tool use reliable
- Write the docstring as an instruction. The model reads it to decide when and how to call the tool.
- Use simple argument types. Strings and integers are filled in far more reliably than nested objects.
- Keep temperature at 0 to 0.3 for agent steps. Raise it only in the step that writes prose.
- Return short tool results. A 5,000-token tool output goes back into the context on every later step.
- Set
recursion_limitin the run config so a confused agent stops instead of looping.
Structured output with JSON mode
Many agent steps do not need tools at all. They need a clean JSON object that the next step can read. The API supports response_format: {"type":"json_object"}, and you can bind it to the LangChain model:
import os, json
from langchain_openai import ChatOpenAI
llm = ChatOpenAI(
base_url="https://api.uncensoredaichatbot.top/v1",
api_key=os.environ["UNCENSORED_KEY"],
model="uncensored",
temperature=0,
)
json_llm = llm.bind(response_format={"type": "json_object"})
msg = json_llm.invoke(
"Classify this support message and answer in JSON with keys 'topic' and 'urgent' (true or false): "
"'My payment went through but my balance did not change.'"
)
data = json.loads(msg.content)
print(data["topic"], data["urgent"])
Always mention JSON and the key names in the prompt itself. JSON mode makes the output parseable, but the model still needs to be told which keys you want. Wrap json.loads in a try block and retry once on failure, since a truncated reply is the one way a JSON response can break. Setting max_tokens high enough for the object prevents truncation.
LangChain also offers llm.with_structured_output(MySchema, method="json_mode") if you prefer Pydantic models. It builds on the same request parameter.
Running agents in parallel without hitting 429
Agents create bursts. One user request can fan out to several model calls, and a batch job can launch dozens at once. The limits to design for:
| Key type | Concurrent requests | Requests per minute |
|---|---|---|
| Full key | 8 | 300 |
| Trial key | 2 | 60 |
Over a limit you receive HTTP 429 with the code rate_limited (too many per minute) or concurrency (too many at once). A temporary overload also returns 429, with Retry-After: 5. The OpenAI client inside ChatOpenAI retries 429 responses with backoff, which is why max_retries=3 above is a sensible default.
For batches, cap the parallelism in LangChain rather than relying on retries:
import os
from langchain_openai import ChatOpenAI
llm = ChatOpenAI(
base_url="https://api.uncensoredaichatbot.top/v1",
api_key=os.environ["UNCENSORED_KEY"],
model="uncensored",
)
questions = [f"Summarize idea number {i} in one sentence." for i in range(40)]
answers = llm.batch(questions, config={"max_concurrency": 6})
print(len(answers))
Six leaves headroom under the limit of 8 for any other traffic on the same key. Remember that a streamed request holds its slot until the stream finishes, so a UI that streams to several users needs its own queue in front of the agent.
Memory and debugging for longer agent runs
Once the single-task agent works, two problems show up. The first is memory: an agent that serves a conversation needs the earlier turns. In LangGraph you attach a checkpointer and pass a thread ID, so each user's messages accumulate on their own thread. The second is visibility: when something fails at step four of six, you need to see steps one to three.
import os
from langchain_openai import ChatOpenAI
from langchain_core.tools import tool
from langgraph.prebuilt import create_react_agent
from langgraph.checkpoint.memory import MemorySaver
llm = ChatOpenAI(
base_url="https://api.uncensoredaichatbot.top/v1",
api_key=os.environ["UNCENSORED_KEY"],
model="uncensored",
temperature=0.2,
)
@tool
def add(a: int, b: int) -> int:
'''Add two integers.'''
return a + b
agent = create_react_agent(llm, [add], checkpointer=MemorySaver())
cfg = {"configurable": {"thread_id": "user-42"}, "recursion_limit": 12}
for step in agent.stream({"messages": [("user", "What is 19 plus 23?")]}, cfg, stream_mode="values"):
step["messages"][-1].pretty_print()
Streaming with stream_mode="values" prints the state after each step, which doubles as a trace. The in-memory saver forgets everything on restart, so swap it for a persistent one before you ship.
Keep an eye on history size. The context window is 100,000 tokens, but every extra token is resent on each step and billed as input. A trimming step that keeps the system message and the last dozen messages is cheap to write and often cuts the cost of long threads by half or more. Check the numbers on your own runs rather than trusting an estimate.
Cost of an agent run
Agents cost more than single calls because every step resends the conversation, including earlier tool results. Pricing is $0.15 per 1M input tokens and $0.50 per 1M output tokens, from prepaid credit.
Take an agent that makes 6 model calls to finish a task. Suppose the prompt grows from 1,500 to 5,000 tokens across the calls, for about 19,500 input tokens in total, and the model writes about 150 tokens per call, or 900 in total.
- Input: 19,500 x $0.15 / 1M = $0.002925
- Output: 900 x $0.50 / 1M = $0.00045
- Total: $0.003375 per task, about a third of a cent.
A thousand such tasks cost $3.375. The biggest saving is trimming tool output and old steps. Failed or refused requests are not charged. Top-ups run from $20 to $500 with bonuses from $50, paid by crypto (USDT on TRC20, USDC on Base); see the pricing page.
What to build first
Agent demos tend to start ambitious and end fragile. A better first project is a single-purpose agent with a clear success test, for example one that reads a support message, looks up a fake order in a Python dictionary and drafts a reply. You know what the right answer is, so you can tell at a glance whether tool calling works.
Grow the project in small steps. Add a second tool only after the first one succeeds on twenty varied inputs. Write those twenty inputs into a file and rerun them after every change to the prompt or the tool descriptions. When a run fails, read the message trace, fix one thing, and rerun. This habit catches regressions early and tells you cleanly whether a problem comes from your code, your prompt or the model itself.
Where to go next
Start with the single-call connection test, then add one tool, then add a second. Resist building a five-tool agent on the first day. Each tool you add is another place for argument errors to appear, and it is easier to find them one at a time.
The API documentation lists every supported request field, including stop, seed and the penalties, which LangChain passes through. If you are choosing between providers for the same agent code, the page on this API compared with OpenRouter covers that decision. Because your agent only knows a base URL and a model name, switching later is a two-line change, which makes it cheap to try this endpoint on a real workload.
More guides
Questions and answers
Your key is one form away
Create an account, copy the key, change the base URL. That is the whole setup.