Last updated
Character AI API Integration Guide
Migrating from Character AI to a self-hosted or API-based solution gives you full control over context, style, and censorship. This guide walks you through integrating an uncensored LLM that mimics the familiar chat interface but offers deeper customization and no monthly subscription fees.
Why Replace Character AI with an API?
Character AI is convenient, but it locks your characters into its ecosystem. You cannot save the full context window, tweak the model parameters, or ensure your data stays private. An API solution like uncutly AI gives you direct access to an uncensored LLM. You control the prompts, the temperature, and the stop sequences. This means your characters behave exactly how you want them to.
Proprietary platforms often refuse content that is perfectly legal. They might cut off a story because of a sensitive keyword. With an uncensored chatbot API, you decide what is allowed. You get a single, reliable endpoint for text generation. This reliability is crucial when you are building a product that depends on consistent character behavior. You are not at the mercy of a platform's arbitrary moderation team.
Step 1: Get Your API Key
Start by creating an account on the provider's dashboard. You can sign in with Google or use a simple email and password. No phone number is required. Once registered, navigate to the API key section. The system generates a unique key immediately. Copy this key and store it securely in your environment variables.
Every request to the API must include this key in the header. If the key is missing or invalid, the server returns a 401 error. You get a small trial credit to test the integration before spending money. This trial credit lasts for seven days. It is a good way to verify your setup works correctly.
Step 2: Configure the Base URL
Most modern LLM clients expect an OpenAI-compatible interface. You need to point your SDK to the correct base URL. For this service, the endpoint is https://api.uncutlyai.com/v1. This URL structure mirrors the standard OpenAI API. It means you can use existing libraries without major code changes.
Update your configuration object to include this base URL. Also, set the API key in the authorization header. The model ID you will use is simply "uncensored". This model is tuned for fewer refusals and better creative freedom. It handles long contexts well, up to 100,000 tokens. This length allows for deep character histories.
Step 3: Send Your First Chat Completion
Construct a POST request to the /v1/chat/completions endpoint. The body should contain a list of messages. Each message has a role like "system", "user", or "assistant". The system message defines the character's personality. The user messages drive the conversation.
Here is how you structure the request:
curl https://api.uncutlyai.com/v1/chat/completions \
-H "Authorization: Bearer $API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "uncensored",
"messages": [{"role": "user", "content": "Show me the API endpoint for text generation"}]
}'Send this request to see the model respond. The server processes the tokens and returns a text completion. You can set parameters like temperature to control creativity. Higher values make the character more unpredictable. Lower values make it more consistent. This flexibility lets you fine-tune the voice.
Step 4: Handle Streaming Responses
Chat applications feel sluggish if the entire response waits until the end. Streaming solves this. Set the stream parameter to true. The server sends back a series of Server-Sent Events (SSE). Each event contains a small chunk of text.
Your client code must parse these chunks and display them in real-time. This creates the illusion of a human typing. It significantly improves the user experience. The final chunk often contains the token usage statistics. You can use this data to track your costs accurately.
from openai import OpenAI
client = OpenAI(base_url="https://api.uncutlyai.com/v1", api_key="YOUR_KEY")
resp = client.chat.completions.create(
model="uncensored",
messages=[{"role": "user", "content": "Summarise this thread without softening it."}],
)
print(resp.choices[0].message.content)Ensure your streaming handler catches any network errors. A broken stream can leave the UI in a loading state. Always close the connection when the stream finishes or fails.
Step 5: Manage Tokens and Costs
Understanding token costs is essential for budgeting. You pay per million tokens. Input tokens cost $0.15 per million. Output tokens cost $0.50 per million. You only pay for tokens that are processed. Errors do not charge you. Refusals do not charge you either.
This prepaid model is transparent. You top up with cryptocurrency. The minimum top-up is $20. You can add $500 at a time. There are no monthly subscriptions. Your credit never expires. This predictability helps you plan your development costs. You know exactly how much each conversation will cost.
Step 6: Implement Function Calling
Advanced characters often need to interact with external tools. Function calling allows the model to return structured data. You define a schema for the function. The model decides when to call it based on the conversation.
For example, a character might need to check the weather. You send the function definition in the request. The model responds with a JSON object containing the function name and arguments. Your code executes the function and sends the result back to the model.
import OpenAI from "openai";
const client = new OpenAI({ baseURL: "https://api.uncutlyai.com/v1", apiKey: process.env.API_KEY });
const resp = await client.chat.completions.create({
model: "uncensored",
messages: [{ role: "user", content: "Draft a villain monologue for my game." }],
});
console.log(resp.choices[0].message.content);This loop continues until the model generates the final text response. It enables dynamic, interactive stories. You are not limited to static text outputs. The model can trigger events in your application.
Step 7: Error Handling and Limits
APIs have limits. You can send 300 requests per minute. Only eight requests can be active simultaneously. The request body must be under 8 MB. If you exceed these limits, you receive a 429 error. Implement exponential backoff in your retry logic.
Handle network errors gracefully. If the server returns a 500 error, wait and retry. Never assume the model will always succeed. Log these errors to identify patterns. Frequent timeouts might indicate you need to adjust your timeout settings.
Step 8: Scale Your Integration
As your user base grows, your API usage will increase. Monitor your token consumption closely. Use the usage data from the streaming responses to track costs. If you notice high costs, consider optimizing your prompts. Shorter system prompts can reduce input tokens.
Consider caching frequent responses. If multiple users ask the same question, serve the cached result. This reduces API calls and saves money. You can also implement rate limiting on your own server. This prevents a single user from consuming all your credit. A well-scaled integration remains fast and reliable.
Common questions
Is this uncensored AI model truly free from refusals?
The model is tuned to answer without content refusals for lawful adult use. It does not block controversial or creative topics. However, there is a hard limit: sexual content involving minors is always refused. This is the only content that will be consistently filtered.
Can I use the official OpenAI SDK with this API?
Yes. The API is fully OpenAI-compatible. You can use the official SDKs by changing the base URL to HTTPS://api.uncutlyai.com/v1 and providing your API key. All standard parameters like temperature and top_p work as expected.
How do I pay for the API credits?
You can top up your account using cryptocurrency. We accept USDT (TRC20) and USDC (Base). You can add any whole amount from $20 to $500. Credits never expire. There are no monthly fees or subscriptions.
What is the context window size?
The model supports a context window of 100,000 tokens. This includes both the prompt and the completion. You can generate up to 16,000 tokens in a single request. If you do not set max_tokens, the default output is 2,048 tokens.
Get your API key
Register, copy the key, update the base URL. That is all you need.