Integrating Unrestricted API: A Step-by-Step Guide for Python
Connecting to an uncensored text model in Python requires more than just an API key; it demands careful handling of context windows and streaming responses. This guide walks you through the essential setup, from authentication to managing token limits, ensuring your application remains stable during long conversations.

Setting Up Your Environment and Authentication
Before writing any code, you need to secure your access to the service. The first step is to create an account and generate your API key. You can sign up using Google or an email and password combination. Once registered, your API key is displayed immediately, so copy it down securely. This key is the only credential you need to authenticate your requests.
Next, install the necessary Python libraries. While you can use requests for simple HTTP calls, using a dedicated SDK often simplifies handling JSON payloads and streaming data. Ensure your Python environment is up to date to avoid compatibility issues with modern JSON parsing libraries. You will need to store your API key in an environment variable or a secure configuration file to prevent accidental exposure in your code repository.
The base URL for all API endpoints is https://api.unrestricted.cc/v1. This is the foundation for all subsequent requests. If you are sending a chat completion or checking model details, this URL remains constant. Make sure your network configuration allows outbound HTTPS traffic to this domain, as firewalls might block API calls if not configured correctly.
Finally, verify your connection by making a simple test request. A basic GET request to the models endpoint can confirm that your key is valid and your network path is clear. If you receive a 401 error, double-check your key. If you get a 402 error, it means you have no credit, and you will need to top up using cryptocurrency. This initial verification saves time when debugging more complex integrations later.
Understanding the Model and Context Window
When integrating the API, it is important to understand the specific model you are interacting with. The API serves a single uncensored open-weight text model, identified by the string uncensored. This model is designed for text-in, text-out interactions, meaning it does not process images, audio, or video. It is optimized for generating coherent text responses based on the input you provide.
The context window for this model is 100,000 tokens. This is a significant capacity that allows for deep memory retention in long conversations. However, it is important to remember that this limit applies to the combined total of your prompt and the model's completion. If your input text is very long, you must leave room for the output. Exceeding this limit will result in an error, so monitor your token usage closely.
Unlike some competitors, this service does not offer model routing or fine-tuning. You are always connecting to the same base model. This simplicity can be an advantage, as you do not need to manage multiple model versions or versions. However, it also means you cannot switch to a smaller or faster model for specific tasks. The trade-off is consistency in behavior across all requests.
When designing your application, consider how you will manage the context window. If you are building a chatbot, you may need to implement a strategy for trimming older messages to stay within the 100,000 token limit. This ensures that the model can still generate a response without hitting the ceiling. Proper context management is key to maintaining a smooth user experience in long-running sessions.
Making Your First API Request
Now that your environment is set up, let's look at how to make a basic API request. The primary endpoint for chat completions is POST /v1/chat/completions. This endpoint accepts a JSON payload containing your messages, the model ID, and various parameters. The model ID is always uncensored, which tells the system which model to use for the generation.
Your message history should be passed as a list of objects, each containing a role and content. Common roles include system, user, and assistant. The system message can be used to set the tone or provide instructions for the model. The user message contains the input, and the assistant message contains the previous response. This structure allows the model to maintain context across multiple turns.
You can also include parameters to control the generation process. Parameters like temperature, top_p, and stop allow you to fine-tune the creativity and output format. For example, setting a lower temperature makes the output more deterministic, while a higher temperature introduces more randomness. These parameters are essential for tailoring the model's behavior to your specific use case.
Finally, handle the response carefully. The API returns a JSON object with the generated text and usage statistics. You should parse this response and extract the content for display in your application. If the response includes an error code, such as 429 for rate limits, you should implement retry logic to handle transient issues gracefully. This ensures your application remains reliable even under heavy load.
Implementing Streaming Responses
For applications that require real-time feedback, streaming responses are essential. The API supports streaming over Server-Sent Events (SSE), which allows you to receive partial responses as they are generated. This is particularly useful for chatbots, where users expect immediate feedback as the model types out its response.
To implement streaming, you need to set the appropriate header in your request. This tells the API to send data in chunks rather than waiting for the full response to complete. Each chunk contains a portion of the text, which you can append to your display buffer. This creates a smooth typing effect for the end user.
One important detail is that the usage statistics are included in the last chunk of the stream. This means you cannot know the total token count until the stream finishes. You should design your UI to handle this by showing the text as it arrives and updating the usage info only at the end. This approach provides a smooth experience without unnecessary delays.
Streaming also helps with memory usage, as you do not need to store the entire response in memory before processing it. You can process each chunk as it arrives, which is beneficial for long outputs. However, be mindful of the rate limit of 300 requests per minute. If you are streaming many concurrent sessions, you may hit this limit faster than with non-streaming requests.
Handling Errors and Rate Limits
Even with a well-designed application, errors will occur. It is important to handle them gracefully to provide a good user experience. The API returns specific error codes that indicate the nature of the problem. A 401 error means your API key is invalid, so you should check your credentials. A 402 error indicates that you have no credit, requiring a top-up. A 429 error signals that you have exceeded the rate limit.
The rate limit is 300 requests per minute per key. If you hit this limit, your requests will be rejected until the window resets. To avoid this, you can implement exponential backoff in your retry logic. This means waiting longer between retries as the number of failures increases. This prevents your application from flooding the API with requests and getting blocked.
Another consideration is the hard content limit. The model refuses requests involving sexual content with minors. If you send such a request, the model will refuse to generate a response. You should handle this by checking the response for refusal indicators and informing the user appropriately. This ensures compliance with the service's terms of use.
Errors and refusals are free, meaning you are not charged for tokens in these cases. This is a helpful feature, as it reduces costs when testing or when the model refuses a prompt. However, valid requests that consume tokens will be charged according to the pricing model. Always monitor your usage to avoid unexpected charges.
When This API Is NOT the Right Choice
While this API is powerful for text generation, it is not suitable for every project. It is a text-in, text-out service, meaning it does not support image, audio, or video generation. If your application requires multimodal capabilities, such as generating images from text or analyzing video content, this API will not meet your needs. You would need to look for a provider that offers these additional features.
Additionally, the service does not offer fine-tuning or model routing. If you need to train a custom model on your own data or switch between different models for different tasks, this service may not be the best fit. The model is fixed, and you cannot customize it beyond the standard parameters. This limitation is important to consider if you require highly specialized or dynamic model behavior.
The pricing model is also a factor. You pay per token, with no free unlimited tier. While the trial credit gives you a head start, you will need to top up using cryptocurrency to continue using the service. If you prefer a subscription model or credit card payments, this service may not align with your payment preferences. The crypto-only top-up process is a specific requirement that not all users may find convenient.
Finally, if you need embeddings or search capabilities, this API does not provide them. It is focused solely on chat completions. If your application relies on semantic search or vector embeddings, you will need to integrate a separate service for those functions. Understanding these limitations helps you decide if this API is the right tool for your specific project.
Addressing Community Questions on Roleplay and Filters
Developers often ask about using this API for roleplay and whether it truly lacks filters. The model is designed to be uncensored, meaning it does not refuse lawful adult, fictional, or controversial topics. This makes it suitable for roleplay applications where users want immersive and unrestricted interactions. However, it is important to note that the model does refuse requests involving sexual content with minors, which is a hard limit.
Users also inquire about the best models for roleplay. Since this API serves a single uncensored model, you do not need to choose between different models. The focus is on the quality of the text generation and the ability to maintain character over long conversations. The 100,000 token context window allows for deep memory, which is important for maintaining consistency in long roleplay sessions.
Another common question is whether the model breaks character or forgets context. With proper context management, the model can maintain character effectively. However, if the context window is full, older messages may be trimmed, which could lead to loss of context. Developers should implement strategies to preserve key character details and plot points within the context limit.
Finally, users often compare this service to others in terms of filter strictness. While this service is uncensored, it is not completely without limits. The refusal of minor-related sexual content is a key distinction. Developers should test their specific use cases to ensure the model behaves as expected. This hands-on testing is the best way to determine if the API meets your roleplay requirements.
Frequently asked questions
How do I top up my credit?
You can top up your credit using cryptocurrency. The service accepts USDT on the TRC20 network or USDC on the Base network. You can add any whole amount between $20 and $500. There is no option for credit cards or PayPal.
What is the context window size?
The context window is 100,000 tokens. This includes both the input prompt and the generated completion. You can use this large window for long conversations, but you must manage the tokens to avoid exceeding the limit.
Does the API support image generation?
No, the API is text-in, text-out only. It does not support image, audio, or video generation. If you need multimodal capabilities, you will need to integrate a separate service for those features.
What happens if I hit the rate limit?
If you exceed 300 requests per minute, you will receive a 429 error. Your requests will be rejected until the rate limit resets. It is recommended to implement exponential backoff in your application to handle this gracefully.
More guides
- Unrestricted LLM for Coding: Security Research Use
- Unlimited LLM API: Why Pay-Per-Token Is Honest
- Build an Unrestricted LLM Chatbot in Python
- Best LLM Without Restrictions: Local vs Hosted
- Unrestricted LLM for LM Studio: Local or Hosted
- Unrestricted LLM Chatbot: The Guide to Uncensored AI
- Uncensored LLM API Cost Calculator: Estimating Your Budget
- Troubleshooting Uncensored LLM Outputs