EN ▾
Base URL https://api.uncensoredaiapis.com/v1Model uncensored
Get API key
Uncensored AIMigration guide

Migrate from OpenAI or OpenRouter to an uncensored AI API

Start a migration by changing the base URL, API key and model ID in a small test client. Run a saved set of your own prompts before switching production traffic: a compatible request format does not imply identical answers. This guide covers configuration, streaming, tool calls and the checks to repeat in LangChain or LlamaIndex.

Migrate from OpenAI or OpenRouter to an uncensored AI API

Updated

Key points

  • Change only three values: base URL https://api.uncensoredaiapis.com/v1, your new key, and model "uncensored".
  • Chat completions, streaming and tool calling work in the OpenAI format; embeddings, images, audio and fine-tuning do not exist.
  • Put base URL, key and model in environment variables so old and new backends run side by side and rollback is one file swap.
  • Set max_tokens explicitly and plan for the 100,000-token context before cutting over.

What changes when you switch

If your app already talks to the OpenAI or OpenRouter chat completions API, moving to this uncensored AI API is a configuration change, not a rewrite. Three values change and everything else in your request code stays as it is: the base URL, the API key, and the model name.

SettingBeforeAfter
Base URLThe OpenAI or OpenRouter URLhttps://api.uncensoredaiapis.com/v1
API keyKey from your current serviceKey from your account here, sent as Authorization: Bearer <key>
ModelA model id such as a GPT or routed model nameuncensored
Endpoint/chat/completionsSame: POST /v1/chat/completions

There is exactly one model, so there is no model catalogue to choose from. GET /v1/models exists and lists it, which keeps SDK helpers and health checks that call it working. Messages, streaming and tool calling use the same OpenAI formats you already send. This page is a hands-on guide; if you want the cost, latency and privacy comparison with OpenRouter, read the OpenRouter uncensored models article instead.

Here is the minimal Python diff. Nothing else in the call changes.

import os
from openai import OpenAI

# before
# client = OpenAI(api_key=os.environ["OPENAI_API_KEY"])
# model = "gpt-4o"

# after
client = OpenAI(
    base_url="https://api.uncensoredaiapis.com/v1",
    api_key=os.environ["API_KEY"],
)
model = "uncensored"

resp = client.chat.completions.create(
    model=model,
    messages=[{"role": "user", "content": "Say hello in five words."}],
    max_tokens=50,
)
print(resp.choices[0].message.content)

For OpenRouter users, the same applies: replace the OpenRouter base URL and key, and drop any routing-specific extras you passed in headers or the request body (see the compatibility table below).

Parameter and feature compatibility

The surface that matters for a chat app is covered. The table separates what is documented as supported, what you should confirm with a test call before depending on it, and what does not exist at all. When in doubt, send the request in a staging environment and compare the response, rather than assuming parity with another service.

FeatureStatusNotes
modelSupportedUse uncensored. One model only.
messages (system, user, assistant, tool roles)SupportedStandard OpenAI message format. Context is 100,000 tokens for prompt plus completion.
max_tokensSupportedUp to the end of the 100,000-token window.
stream: trueSupportedServer-sent events. A final usage chunk is added automatically.
tools, tool_choice, role tool messagesSupportedOpenAI function calling format.
Sampling and stop options (temperature, top_p, stop, and similar)SupportedStandard OpenAI fields, passed through as sent. Re-tune temperature after switching: the same value can feel different on a new model.
Routing extras: fallback model lists, routing preferences, app-attribution headersNot availableThere is one model, so there is nothing to route between. Remove these from requests and config.
EmbeddingsNot availableKeep a separate embeddings source for RAG pipelines.
Image generation, vision, audio, videoNot availableThe API is text only.
Fine-tuningNot availableNo fine-tuning endpoints. Shape behaviour with system prompts.

The practical consequence is that a pipeline using embeddings for retrieval needs two clients: one for your existing embeddings service and one for generation here. That is a normal split, and the env-var approach in the next section keeps it tidy.

Run both side by side with environment variables

The safest migration keeps both backends alive and picks one at runtime. Put the three values that differ into environment variables, and read them in one place. Then you can route a dev environment, a percentage of traffic, or a single feature to the new API without branching your request code.

# .env.openai
LLM_BASE_URL=your-current-base-url
LLM_API_KEY=paste-your-existing-key
LLM_MODEL=gpt-4o

# .env.uncensored
LLM_BASE_URL=https://api.uncensoredaiapis.com/v1
LLM_API_KEY=paste-your-key-here
LLM_MODEL=uncensored

Then a single factory builds the client:

import os
from openai import OpenAI

def make_client() -> tuple[OpenAI, str]:
    client = OpenAI(
        base_url=os.environ["LLM_BASE_URL"],
        api_key=os.environ["LLM_API_KEY"],
    )
    return client, os.environ["LLM_MODEL"]

client, model = make_client()
resp = client.chat.completions.create(
    model=model,
    messages=[{"role": "user", "content": "Reply with the single word: ready"}],
    max_tokens=10,
)
print(model, "->", resp.choices[0].message.content)

The same pattern in Node.js:

import OpenAI from "openai";

export function makeClient() {
  const client = new OpenAI({
    baseURL: process.env.LLM_BASE_URL,
    apiKey: process.env.LLM_API_KEY,
  });
  return { client, model: process.env.LLM_MODEL };
}

const { client, model } = makeClient();
const resp = await client.chat.completions.create({
  model,
  messages: [{ role: "user", content: "Reply with the single word: ready" }],
  max_tokens: 10,
});
console.log(model, "->", resp.choices[0].message.content);

To compare behaviour, run the same prompt set against both configurations, for example with set -a; source .env.uncensored; set +a before your test command. Because the variable names are generic, no code change is needed when you finally retire the old backend, and rolling back is one file swap.

LangChain, LlamaIndex and other OpenAI-compatible clients

Any framework that lets you override the OpenAI base URL will work with this API, because the HTTP contract is the same. You pass the base URL, the key and the model name; the framework does the rest. For LangChain, the langchain_openai package exposes ChatOpenAI:

import os
from langchain_openai import ChatOpenAI

llm = ChatOpenAI(
    base_url="https://api.uncensoredaiapis.com/v1",
    api_key=os.environ["API_KEY"],
    model="uncensored",
    max_tokens=500,
)

print(llm.invoke("Give me a one-line pitch for a noir detective game.").content)

For LlamaIndex, use the OpenAI-compatible LLM class from the llama-index-llms-openai-like package, which is meant for servers that implement the chat completions format but are not OpenAI itself:

import os
from llama_index.llms.openai_like import OpenAILike

llm = OpenAILike(
    api_base="https://api.uncensoredaiapis.com/v1",
    api_key=os.environ["API_KEY"],
    model="uncensored",
    is_chat_model=True,
)

print(llm.complete("Give me a one-line pitch for a noir detective game."))

Two things to remember in framework setups. First, retrieval features that call an embeddings model will still need a different embeddings source, since this API has none. Second, frameworks sometimes assume a model name from an internal list to decide context size or tool support; if you see a warning about an unknown model, that is cosmetic, but check that the context window your framework assumes does not exceed 100,000 tokens. Parameter names differ slightly between libraries (base_url, api_base, baseURL), so check the one your library uses. Other tools that accept a custom OpenAI base URL, such as editor plugins and chat front ends, follow the same three-value pattern.

Testing checklist before you cut over

Run through this list in staging. Each item is quick, and together they catch most migration surprises.

  1. Auth and routing. Call GET /v1/models with your key. A 401 means the key or header is wrong; a 404 means the path is.
  2. Basic completion. Send a one-line prompt with max_tokens set and confirm choices[0].message.content and usage are present.
  3. Streaming. Run your real UI path with stream: true. Make sure your parser tolerates the final usage chunk with an empty choices list.
  4. Tool calls. Execute a full round trip: request, tool_calls, role tool reply, final answer. Check that your code handles replies with no tool call.
  5. Long prompts. Send a prompt near your real maximum. A prompt over 100,000 returns 400; max_tokens is trimmed to fit.
  6. Error handling. Simulate a wrong key (401). Confirm your app reads the JSON error.code and handles 402 no_credit, 403 content_blocked, 429 and 503 upstream_busy sensibly.
  7. Output quality and tone. Replay a sample of real prompts and compare responses to your current model. Prompts that were tuned around another model's refusals or hedging may need simplifying.
  8. Cost tracking. Log usage. Input is $0.15 per million tokens and output $0.50 per million, so your estimates from existing token counts are easy to recompute.

For runnable versions of the streaming, tool and retry steps, see the code examples page.

Common pitfalls

Leaving the old model name in place. The most frequent failure is a request that still says another model id. Read the model from config, as in the env-var example, so it moves together with the base URL.

Sending the old key. A key from another service returns 401. Keys here are tied to one account, one per account, and regenerating one revokes the previous key immediately, so update every deployment after you regenerate.

Missing /v1 in the base URL. The base URL must end in /v1. SDKs append /chat/completions themselves; a base URL without the suffix produces 404 errors.

Relying on a feature that is not there. Embeddings, images, audio and fine-tuning calls will fail. Audit your codebase for them before switching, not after.

Ignoring the output cap. If you do not set max_tokens, the response can run to the end of the window. If another service gave you longer replies by default, set the value explicitly, because a small cap can end replies early with finish_reason: length.

Context overflow. If your current model had a larger window, long histories can exceed 100,000 tokens of prompt plus completion and return 400. Add trimming or summarisation before the switch.

Retrying everything. Retry 429 and 503 only. A 402 means the balance is used up or the trial expired, and retrying will not help. Top up and continue, as described on the pricing page.

Content rules. Lawful adult content and fiction are not refused, but sexual content involving minors is always blocked with a 403, including in fiction and roleplay. The service is for adults and lawful use, so make sure your own product enforces age gating where relevant.

Questions and answers

Do I have to rewrite my code to switch from OpenAI?

Usually no. Change base_url, api_key and the model name to uncensored in your client configuration. Message format, streaming and tool calling follow the same OpenAI format.

Can I keep using OpenRouter alongside this API?

Yes. Read base URL, key and model from environment variables and point each environment or feature at the backend you want. Both can run in parallel during a gradual migration.

What happens to my embeddings or image calls?

They will not work here. The API is text only, with no embeddings, images, audio, video or fine-tuning, so keep a separate source for those.

Does LangChain work with this uncensored AI API?

Yes. Use ChatOpenAI from langchain_openai with base_url set to https://api.uncensoredaiapis.com/v1, your key and model="uncensored". Any client that accepts a custom OpenAI base URL follows the same pattern.

Your key is one form away

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