EN ▾
Get API key

Unrestricted LLM API in Python: OpenAI SDK Setup

Using an unrestricted LLM API from Python takes about ten lines with the official OpenAI SDK. Change the base URL, pass your key, set the model to uncensored, and the rest is ordinary chat completions code.

Updated

Key points

  • Install the openai package, set base_url to the service URL, and use the model ID uncensored.
  • Streaming, JSON mode and tool calling work through the same SDK calls you already know.
  • Handle HTTP 429 with a Retry-After wait and cap your worker count at 8 (2 on a trial key).
  • Cost is $0.15 per 1M input and $0.50 per 1M output tokens, so a typical call costs a fraction of a cent.
Glowing coiled line connecting a laptop to a server cube, illustrating a Python client calling an LLM API

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

Get API key

The short version

If you search for unrestricted llm api python, you probably want a working snippet before an explanation, so here it is. Install the SDK with pip install openai, then run:

from openai import OpenAI

client = OpenAI(
    base_url="https://api.unrestrictedaiimage.cc/v1",
    api_key="YOUR_API_KEY",
)

resp = client.chat.completions.create(
    model="uncensored",
    messages=[{"role": "user", "content": "Describe a thunderstorm over a harbor in two sentences."}],
)
print(resp.choices[0].message.content)
print(resp.usage)

That is the whole integration. The service speaks the OpenAI chat completions format, so the SDK, its types and its error classes all behave as documented. The model ID is uncensored. It is one open-weight model, tuned to answer without content refusals for lawful adult use, run by an independent provider. Despite the site name, this is a text API only: no images, audio, video, embeddings or fine-tuning.

Get a key and keep it out of your code

Create an account with Google or with email and password, then open the key page. A one-click trial of $0.50 is available there, valid for 7 days, one per person, with no payment details needed. You can start from the API key page.

Do not paste the key into source files. Read it from an environment variable:

export UNRESTRICTED_API_KEY="YOUR_API_KEY"
import os
from openai import OpenAI

client = OpenAI(
    base_url="https://api.unrestrictedaiimage.cc/v1",
    api_key=os.environ["UNRESTRICTED_API_KEY"],
)

The SDK also reads OPENAI_API_KEY and OPENAI_BASE_URL from the environment if you do not pass them in code. That is handy for tools built on the SDK, because you can redirect them without editing their source: set both variables and the tool talks to this service instead.

To confirm the key works before writing anything bigger, list the models. It should return the single ID uncensored:

for m in client.models.list():
    print(m.id)

Chat, system prompts and sampling

A real call usually has a system prompt, some history, and a few sampling settings. Temperature, top_p, stop, seed and the frequency and presence penalties are passed through to the model, so you can use them the way you would elsewhere.

resp = client.chat.completions.create(
    model="uncensored",
    messages=[
        {"role": "system", "content": "You are a direct, plain-spoken research assistant."},
        {"role": "user", "content": "List five weak points in a typical password reset flow."},
    ],
    temperature=0.7,
    top_p=0.95,
    seed=42,
    max_tokens=600,
)
print(resp.choices[0].message.content)

max_tokens is optional. Without it, the completion can use whatever is left of the 100,000 token window after your prompt. In production code a cap is still a good habit, because output tokens cost more than input tokens and a runaway answer is the easiest way to spend money you did not plan to spend.

A note on seeds: setting seed makes runs more repeatable, which helps when you compare two prompt versions, but treat it as a nudge rather than a guarantee. If you need identical text every time, store the first answer instead of regenerating it. For creative work, a temperature between 0.7 and 1.0 gives more varied prose, while 0.2 or lower suits extraction and classification tasks where you want the same answer on each run.

Keep the conversation history on your side. The API is stateless: each request must carry the full list of messages you want the model to see, and that list counts against the context window and against your input bill.

Streaming responses

For anything a person watches, stream. Set stream=True and iterate over the chunks. The service sends server-sent events and reports usage at the end of the stream, so ask for it if you want to log cost:

stream = client.chat.completions.create(
    model="uncensored",
    messages=[{"role": "user", "content": "Write a short scene set in a night market."}],
    stream=True,
    stream_options={"include_usage": True},
)

text = []
for chunk in stream:
    if chunk.choices and chunk.choices[0].delta.content:
        piece = chunk.choices[0].delta.content
        text.append(piece)
        print(piece, end="", flush=True)
    if getattr(chunk, "usage", None):
        print("\nusage:", chunk.usage)

full_text = "".join(text)

One detail matters for limits: a streamed request holds its concurrency slot until the stream ends. If your code breaks out of the loop early, close the stream (use a with block, or call stream.close()) so the slot is released. Otherwise a few abandoned streams can leave you with fewer free slots than you think.

JSON mode and tool calling

For structured output, use JSON mode. It makes the model return a valid JSON object, but you still have to describe the fields you want in the prompt:

import json

resp = client.chat.completions.create(
    model="uncensored",
    response_format={"type": "json_object"},
    messages=[
        {"role": "system", "content": "Reply with JSON: {\"title\": str, \"tags\": [str]}"},
        {"role": "user", "content": "Summarise: a retired detective returns to a flooded town."},
    ],
)
data = json.loads(resp.choices[0].message.content)
print(data["title"], data["tags"])

Tool calling follows the OpenAI shape: pass tools, optionally tool_choice, read tool_calls from the reply, run your function, and send the result back as a message with role: "tool".

tools = [{
    "type": "function",
    "function": {
        "name": "get_order_status",
        "description": "Look up an order by id",
        "parameters": {
            "type": "object",
            "properties": {"order_id": {"type": "string"}},
            "required": ["order_id"],
        },
    },
}]

messages = [{"role": "user", "content": "Where is order A-1042?"}]
first = client.chat.completions.create(model="uncensored", messages=messages, tools=tools)
call = first.choices[0].message.tool_calls[0]

messages.append(first.choices[0].message)
messages.append({
    "role": "tool",
    "tool_call_id": call.id,
    "content": json.dumps({"status": "shipped"}),
})
final = client.chat.completions.create(model="uncensored", messages=messages, tools=tools)
print(final.choices[0].message.content)

In a real agent you will loop: call the model, run any requested tools, append the results, and call again until the reply has no tool calls. Put a hard limit on the number of rounds, five or ten is usually plenty, so a confused model cannot keep you in a loop that burns credit.

Check that tool_calls is not empty before indexing into it; the model may answer directly. Parse the arguments with json.loads(call.function.arguments) and handle bad JSON, as you would with any model.

Rate limits, 429 errors and retries

A full key allows 8 concurrent requests and 300 requests per minute. A trial key allows 2 concurrent and 60 per minute. The request body can be up to 8 MB. Going over returns HTTP 429, and the error code tells you which limit you hit: rate_limited for requests per minute, concurrency for too many at once. Temporary overload also returns 429, with a Retry-After: 5 header.

The SDK retries a couple of times by default, but you can control it. A small wrapper that respects Retry-After:

import time
from openai import RateLimitError

def chat(messages, tries=5):
    for attempt in range(tries):
        try:
            return client.chat.completions.create(model="uncensored", messages=messages)
        except RateLimitError as e:
            wait = int(e.response.headers.get("Retry-After", 5))
            time.sleep(wait * (attempt + 1))
    raise RuntimeError("still rate limited after retries")

For batch jobs, do not rely on retries alone. Cap parallelism so you never exceed your concurrency limit:

from concurrent.futures import ThreadPoolExecutor

prompts = ["Idea %d for a short story" % i for i in range(40)]

def run(p):
    return chat([{"role": "user", "content": p}]).choices[0].message.content

with ThreadPoolExecutor(max_workers=8) as pool:   # use 2 on a trial key
    results = list(pool.map(run, prompts))

Each response includes X-Request-Id, X-Balance-USD, X-RateLimit-Limit-Requests and X-RateLimit-Limit-Concurrency. To read them with the SDK, use client.chat.completions.with_raw_response.create(...) and look at .headers. Logging the request ID makes support questions much easier to answer.

What it costs per call

Price is $0.15 per 1M input tokens and $0.50 per 1M output tokens, paid from prepaid credit. Failed or refused requests are not charged and credit never expires. The pricing page lists the details.

Worked example: a batch of 10,000 requests, each with 1,500 input tokens and 400 output tokens.

  • Input: 10,000 x 1,500 = 15,000,000 tokens = 15 x $0.15 = $2.25
  • Output: 10,000 x 400 = 4,000,000 tokens = 4 x $0.50 = $2.00
  • Total: $4.25

Read resp.usage.prompt_tokens and resp.usage.completion_tokens and compute the same sum in code to keep a running spend log. Top-ups are any whole amount from $20 to $500, paid in crypto (USDT on TRC20 or USDC on Base), with a bonus of 5% from $50, 10% from $100 and 15% from $200. The docs cover the rest of the request format, and the text service overview explains what the site offers.

One hard rule applies to everything you send: no sexual content involving minors. The model is tuned for lawful adult use otherwise, and prompts are not used for training.

Questions and answers

Which Python library should I use?

The official openai package works as is. Set base_url and api_key on the client and use the model ID uncensored. Any library that can talk to an OpenAI-compatible endpoint, such as plain requests or httpx, also works.

Does it support async Python?

Yes, through the same SDK. Use AsyncOpenAI with the same base_url, api_key and model, and keep your concurrent tasks within 8 for a full key or 2 for a trial key.

Why do I get HTTP 429?

Either you exceeded requests per minute (error code rate_limited), you had too many requests open at once (concurrency), or the service was briefly overloaded. For overload, wait for the Retry-After value of 5 seconds and try again.

Can I use it with LangChain or other frameworks?

Any framework that lets you set an OpenAI-compatible base URL and API key can use it. Pass the service URL, your key and the model name uncensored.

Does this generate images?

No. Despite the domain name, it is a text-only API. There is no image, audio or video generation.

Your key is one form away

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

Start with trial credit

Email and password, key on screen right away.