Unrestricted AIBuild an Unrestricted AI Agent with Tool Calling
Build an Unrestricted AI Agent with Tool Calling
An unrestricted AI agent is a loop around a model that answers without content refusals: the model asks for a tool, your code runs it, and the result goes back until the task is done. This article builds that loop in Python and works out what a run costs.

Key points
- The agent loop needs only chat completions, tools, and results sent back as role tool.
- You run the tools. The model proposes calls, your code validates and executes them.
- Cap steps, handle 429 with Retry-After, and respect 8 concurrent requests.
- A 10-step run with 6,000 tokens of context per step costs about $0.0105.
What an agent is in this setup
An unrestricted ai agent sounds like a product, but it is a pattern. You give a model a goal and a list of functions it may call. The model replies either with text or with a request such as "call search_notes with this query". Your program runs the function, appends the result to the conversation, and asks the model again. The loop ends when the model answers in plain text or when you stop it.
The word unrestricted refers to the model, not to your code. This endpoint serves one open-weight model, tuned to answer without content refusals for lawful adult use. In an agent that matters in a practical way: a model that declines a step halfway through breaks a long chain, while one that stays on task lets you build tools for fiction pipelines, moderation research, red-team tooling for your own systems, or any adult-oriented workflow that general assistants tend to interrupt. The hard limit remains: no sexual content involving minors.
The API gives you what you need and nothing more. POST /v1/chat/completions with tools and tool_choice, streamed tool_calls, JSON mode, and a 100,000-token window. There is no built-in agent runtime, memory store or hosted tool, so everything stateful lives in your code. That is a feature when you want control.
The core loop in Python
The following agent has two tools, a calculator and a note lookup, and stops after at most eight model calls.
import json
import os
from openai import OpenAI
client = OpenAI(
base_url="https://api.unrestrictedaichat.cc/v1",
api_key=os.environ["UNRESTRICTED_KEY"],
)
NOTES = {"harbour": "The inspector takes bribes on Thursdays.",
"ledger": "Page 12 is torn out."}
def lookup_note(topic):
return NOTES.get(topic, "no note found")
def add(a, b):
return a + b
REGISTRY = {"lookup_note": lookup_note, "add": add}
TOOLS = [
{"type": "function", "function": {
"name": "lookup_note",
"description": "Return the saved note for a topic",
"parameters": {"type": "object",
"properties": {"topic": {"type": "string"}},
"required": ["topic"]}}},
{"type": "function", "function": {
"name": "add",
"description": "Add two numbers",
"parameters": {"type": "object",
"properties": {"a": {"type": "number"}, "b": {"type": "number"}},
"required": ["a", "b"]}}},
]
def run_agent(goal, max_steps=8):
messages = [
{"role": "system", "content": "You are a research agent. Use tools when needed, then answer briefly."},
{"role": "user", "content": goal},
]
for step in range(max_steps):
r = client.chat.completions.create(
model="uncensored", messages=messages, tools=TOOLS, tool_choice="auto"
)
msg = r.choices[0].message
messages.append(msg)
if not msg.tool_calls:
return msg.content
for call in msg.tool_calls:
fn = REGISTRY.get(call.function.name)
try:
args = json.loads(call.function.arguments)
result = str(fn(**args)) if fn else "unknown tool"
except Exception as exc:
result = "tool error: " + str(exc)
messages.append({"role": "tool", "tool_call_id": call.id, "content": result})
return "stopped: step limit reached"
print(run_agent("What does the harbour note say, and what is 12 plus 30?"))
Several things in that code are deliberate. Tool arguments arrive as a JSON string, so you parse them yourself and treat a parse failure as a normal tool error rather than an exception that kills the run. Errors go back to the model as tool output, which lets it correct a bad argument on the next turn. Unknown tool names are handled instead of trusted. And the step cap means a confused model cannot loop forever on your credit.
Make tool use reliable
Write tool descriptions like instructions
The model chooses tools from their names and descriptions. "Return the saved note for a topic" is better than "notes". List the valid values in the description or use enum in the schema when a parameter has a closed set.
Keep the toolset small
Five well-described tools beat twenty overlapping ones. If you have many, route first: use a cheap classification call to pick a subset, then run the agent with only those tools.
Use JSON mode for planning steps
Not every step needs a tool call. For a planner or a router, ask for a structured result with response_format={"type": "json_object"} and name the keys in the prompt. Then branch on the parsed object in your own code. Always wrap parsing in a try block, because a model can still produce an invalid object, and a retry with the error text appended usually repairs it.
plan = client.chat.completions.create(
model="uncensored",
response_format={"type": "json_object"},
messages=[
{"role": "system", "content": "Return JSON with keys steps (list of strings) and needs_tools (boolean)."},
{"role": "user", "content": "Goal: summarise every note about the harbour."},
],
)
print(json.loads(plan.choices[0].message.content))
Never execute blindly
The model proposes arguments, and your code decides. Anything with side effects, such as shell commands, file writes, payments or messages to real people, needs an allowlist and, for risky actions, a human confirmation step. A model that does not refuse will also not stop to ask whether a request is wise, so the guardrails belong in your program.
Limits, retries and parallel agents
A full key allows 8 concurrent requests and 300 requests per minute. A trial key allows 2 and 60. An agent that fans out into parallel sub-agents hits the concurrency cap first. When it does, the API returns HTTP 429 with the error code concurrency. Hitting the per-minute cap gives rate_limited. Temporary overload also gives 429, with a Retry-After: 5 header.
Use a semaphore so you never exceed your allowance, and add a retry that honours the header:
import asyncio
from openai import AsyncOpenAI, RateLimitError
aclient = AsyncOpenAI(
base_url="https://api.unrestrictedaichat.cc/v1",
api_key=os.environ["UNRESTRICTED_KEY"],
)
gate = asyncio.Semaphore(6)
async def ask(messages):
async with gate:
for attempt in range(4):
try:
return await aclient.chat.completions.create(
model="uncensored", messages=messages
)
except RateLimitError as exc:
wait = int(exc.response.headers.get("Retry-After", 2 ** attempt))
await asyncio.sleep(wait)
raise RuntimeError("still rate limited")
Setting the gate to 6 instead of 8 leaves room for a second script on the same key. If you stream inside an agent, remember that a streamed request holds its slot until the stream ends. Streaming is good for showing progress to a user, but for background steps a plain call frees the slot sooner.
Keeping context under control
Each step resends the whole message list, so the prompt grows as tool results pile up. The window is 100,000 tokens for prompt plus completion, which is generous but not infinite. Three habits help.
- Truncate tool output before you append it. A 20,000-token web page rarely needs to be kept whole; keep the relevant 800 tokens.
- After a long sub-task, replace its messages with a short summary written by the model.
- Log token usage from the
usagefield of each response, and stop a run that exceeds a budget you set.
The X-Balance-USD response header shows your remaining credit, so a long-running worker can pause itself when the balance falls under a threshold.
Where an unrestricted agent is useful
Agents that run on a model without refusals suit work where a mainstream assistant would stall. A few concrete ideas:
- A fiction pipeline in which one step drafts a scene, a second checks it against a character sheet through a lookup tool, and a third rewrites weak passages.
- A moderation research bench that classifies and rewrites difficult user messages so you can test your own filters against realistic input.
- A companion or roleplay service for adults in which the agent keeps a memory store, fetches facts about the user's characters and writes in a stable voice.
- A data cleaning helper that reads messy, offensive or graphic text from public sources and extracts structured fields from it.
In each case the model itself is the least interesting part. The value comes from the tools, the memory and the checks you wrap around it. Use the service for lawful adult use only, keep a human in the loop for anything that touches other people, and remember the fixed rule that content sexualising minors is never allowed.
What an agent run costs
Billing is $0.15 per 1M input tokens and $0.50 per 1M output tokens. Because every step resends the history, input dominates agent cost. Take a run of 10 steps with an average of 6,000 input tokens and 300 output tokens per step.
- Input: 10 x 6,000 = 60,000 tokens, which is 60,000 / 1,000,000 x $0.15 = $0.009.
- Output: 10 x 300 = 3,000 tokens, which is 3,000 / 1,000,000 x $0.50 = $0.0015.
- Total: $0.0105 per run.
A hundred such runs cost $1.05, and a $20 top-up covers roughly 1,900 of them. Failed or refused requests are not charged, and credit never expires. Top-ups accept any whole amount from $20 to $500, with +5% from $50, +10% from $100 and +15% from $200. You can pay by crypto (USDT on TRC20, USDC on Base); see pricing for details.
New accounts can claim $0.50 of trial credit with one click on the key page, no card needed, valid for 7 days. At about $0.0105 per run that is more than 40 test runs. The documentation covers each parameter, and since agents often handle sensitive material, the page on cost and privacy trade-offs is worth reading. For the record, prompts sent to the API are not used for training.
More guides
On this page
- What 'No Log' Really Means for AI APIs
- What 'No Log' Really Means for AI APIs
- What 'No Log' Really Means for AI APIs
- What 'No Log' Really Means for AI APIs
- What 'No Log' Really Means for AI APIs
- What 'No Log' Really Means for AI APIs
- What 'No Log' Really Means for AI APIs
- What 'No Log' Really Means for AI APIs
Questions and answers
Does the API support function calling for agents?
Yes. Send tools and tool_choice to /v1/chat/completions, read tool_calls from the reply (they can be streamed), and return results as messages with role tool.
How many agents can I run in parallel?
A full key allows 8 concurrent requests and 300 per minute; a trial key allows 2 and 60. Above that you receive HTTP 429 with the code concurrency or rate_limited.
Can the model execute code or browse by itself?
No. It only returns text and tool call requests. Your program runs every tool, so you control what the agent can actually do.
Is anything still off limits?
Sexual content involving minors is blocked. The service is intended for lawful adult use.
Your key is one form away
Create an account, copy the key, change the base URL. That is the whole setup.