EN ▾
Start now

Integrate Uncensored Inference API with Python SDK

Developers often need a straightforward way to send text to an uncensored model without the baggage of image or audio processing. This guide provides a tested Python checklist, showing how to configure the SDK for text-only streaming and handle errors effectively.

Developer integrating uncensored text API with Python on a laptop screen

Understanding the API Structure

The foundation of our service is a hosted, OpenAI-compatible chat-completions API. It serves a single uncensored open-weight text model, meaning you send text in and receive text out. The model identifier you must use for all requests is uncensored. This simplicity ensures that your integration focuses purely on text generation without the complexity of multimodal inputs.

The base URL for all your API calls is https://api.apiinference.com/v1. From this root, you will interact with three specific endpoints. You will use POST /v1/chat/completions for standard chat interactions, POST /v1/responses for alternative response formats, and GET /v1/models to verify available configurations. There are no embeddings, image generation, audio processing, or video capabilities, so your code does not need to handle binary data or complex media streams.

Context window management is critical for long conversations. Our API supports a context window of 100,000 tokens, which includes both the prompt and the completion together. This allows for extensive context retention, making it suitable for detailed analysis or long-form content generation. However, since the model is text-only, you must ensure your input does not exceed this limit to avoid truncation.

When integrating, remember that this is an independent service. It is not an official product of any major tech vendor, nor does it serve another company's model. You should treat it as a standalone text inference engine. Always check the vendor's own documentation for current prices and limits if you are comparing it to other services, but for our API, the rules are fixed: text in, text out, uncensored.

Authentication and Key Management

Getting started with our API requires a simple signup process. You can continue with Google or use an email and password combination. Once you create an account, your API key is shown immediately, allowing you to start making requests without delay. This key is your primary identifier for authentication and must be kept secure to prevent unauthorized usage of your prepaid credit.

Authentication is handled via the API key, which you include in the headers of your HTTP requests. If the key is invalid or missing, the API will return a 401 error. This ensures that only authorized users can access the service. It is important to store your key in environment variables or a secure configuration file in your Python application to avoid exposing it in version control systems.

The service operates on a prepaid credit system, meaning there are no monthly subscriptions or recurring fees. You pay for what you use, and any unused credit never expires. This model is particularly appealing for developers who want predictable costs without the commitment of a subscription. Errors and refusals are free, so you do not pay for failed requests or content that does not meet your criteria.

When managing your keys, be aware of the rate limits. You are allowed 300 requests per minute per key. If you exceed this limit, the API will return a 429 error, indicating that you have hit the rate limit. This is useful for preventing abuse and ensuring fair usage across all users. You can implement exponential backoff in your Python script to handle these errors gracefully.

Payment and Credit Top-Up

Our API uses a unique payment model that relies exclusively on cryptocurrency. You can top up your account using USDT on the TRC20 network or USDC on the Base network. The minimum top-up amount is $20, and the maximum is $500. This range allows for flexible funding without requiring large upfront investments. You cannot use credit cards, PayPal, or bank transfers, so ensure your wallet is set up to handle these specific tokens.

When you top up, you may receive bonus credit depending on the amount. For top-ups of $50 or more, you get a bonus ranging from +5% to +15%. This bonus is added to your balance, giving you more tokens to work with. The bonus credit is charged by real token usage, so it behaves exactly like your base credit. This incentivizes larger top-ups and provides extra value for heavy users.

The pricing structure is straightforward: $0.15 per 1 million input tokens and $0.50 per 1 million output tokens. These rates are applied to your actual token usage, so you only pay for what you consume. There are no hidden fees or surcharges. This transparency makes it easy to budget for your projects, especially if you are building an application with variable usage patterns.

Since payments are crypto-only, the process is fast and borderless. You can top up from anywhere in the world without worrying about international bank fees. However, you must ensure you are using the correct network (TRC20 for USDT or Base for USDC) to avoid losing your funds. Always double-check the network before sending tokens to your account address.

Streaming and Real-Time Output

For applications that require real-time feedback, our API supports streaming over Server-Sent Events (SSE). This allows you to receive text chunks as they are generated, rather than waiting for the entire response to complete. Streaming is particularly useful for chat interfaces, where users expect immediate feedback. It also helps in managing latency for long responses, as you can start displaying text as soon as the first token is ready.

To implement streaming in Python, you need to set the appropriate headers and handle the SSE stream. The API returns usage information in the last chunk of the stream, which includes the token counts for input and output. This allows you to track your credit usage in real-time and adjust your application's behavior accordingly. You can parse these chunks to build a smooth user experience.

Streaming also helps in managing context window limits. Since you receive tokens incrementally, you can monitor the total token count and stop the generation if it approaches the 100,000-token limit. This prevents unexpected truncation and ensures that your application behaves predictably. You can also implement logic to truncate old context if needed, though the API handles the context window automatically.

When using streaming, it is important to handle network interruptions gracefully. If the connection drops, you may need to retry the request or resume from the last received chunk. Python libraries like requests or aiohttp provide tools for handling SSE streams efficiently. Make sure to test your implementation under various network conditions to ensure reliability.

Error Handling and Troubleshooting

Effective error handling is important for a reliable Python integration. Our API returns specific HTTP status codes to indicate different types of errors. A 401 error means the API key is invalid or missing, so you should verify your key and ensure it is included in the request headers. A 402 error indicates that you have no credit left, which means you need to top up your account before making more requests. A 429 error signals that you have hit the rate limit of 300 requests per minute.

When encountering a 429 error, it is best to implement exponential backoff in your Python script. This means waiting a short period before retrying the request, and increasing the wait time with each subsequent failure. This prevents overwhelming the API and reduces the chance of hitting the rate limit again. You can also monitor your request rate to stay within the limit.

Another common issue is handling refusals. Our API has a hard content limit: it refuses requests involving sexual content with minors. However, it does not refuse lawful adult, fictional, security-research, or controversial topics. If you receive a refusal, check your prompt to ensure it does not violate this specific limit. Other refusals may occur due to technical issues, so check the API status or contact support if needed.

Logging errors is essential for debugging. Record the HTTP status code, the request payload, and the response body. This information helps you identify the root cause of issues and optimize your integration. Use Python's logging module to capture these details and store them in a file or database for later analysis. This practice improves the maintainability of your application.

When Our API Is Not the Right Choice

While our API is excellent for text generation, it may not be the right choice for every project. If your application requires image generation, audio synthesis, or video processing, our API cannot handle these tasks. It is a text-only service, so you will need to integrate with other providers for multimodal capabilities. Similarly, if you need embeddings for vector search, our API does not provide this feature.

Fine-tuning is another area where our API does not excel. If you need to train a custom model on your specific dataset, you will need to look for a provider that offers fine-tuning services. Our API serves a single uncensored open-weight model, so you cannot train a custom version of it. This makes it less suitable for projects requiring highly specialized model behavior.

Model routing is also not supported. If you want to switch between different models based on the task, our API only serves the uncensored model. You cannot route requests to multiple models or use a router to select the best model for each input. This limits flexibility for applications that require diverse model capabilities.

Finally, if you need on-premises deployment for data privacy or compliance reasons, our API is hosted, so you cannot run it locally. If you require full control over the infrastructure, you might prefer a self-hosted solution. However, for most text-based applications, our API provides a reliable and uncensored alternative without the overhead of managing your own servers.

Community Insights and Reddit Discussions

Developers often discuss integration challenges and feature requests on Reddit. Threads on r/LocalLLaMA frequently mention the desire for low-latency text generation and easy API access. Users appreciate the simplicity of our OpenAI-compatible endpoint, which allows them to swap out other providers with minimal code changes. They often compare our service to local TTS solutions, noting that our text-only focus reduces complexity.

On r/LovingOpenSourceAI, users talk about the value of uncensored models for creative writing and role-playing. They appreciate that our API does not refuse controversial topics, which is important for certain use cases. Some users mention that while other providers offer free tiers, our prepaid model offers more control over costs. They often discuss the bonus credit system as a significant advantage for heavy users.

Threads on r/codex highlight the importance of rate limits and error handling. Developers share tips on managing 429 errors and optimizing request frequency. They also discuss the benefits of streaming for real-time applications. Many users note that our API's simplicity makes it easier to integrate into existing Python projects compared to more complex multimodal APIs.

Overall, the community values our API for its reliability and uncensored nature. Users often recommend it for projects that require high-quality text generation without the restrictions of mainstream models. They also appreciate the transparent pricing and the ability to top up with crypto. These insights help new users understand how to best utilize our API in their workflows.

Frequently asked questions

How do I top up my account?

You can top up your account using USDT on the TRC20 network or USDC on the Base network. The minimum amount is $20, and the maximum is $500. You cannot use credit cards or PayPal.

What happens if I hit the rate limit?

If you exceed 300 requests per minute, you will receive a 429 error. You should implement exponential backoff in your Python script to retry the request after a short delay.

Does the API support image generation?

No, the API is text-only. It serves the 'uncensored' model for text input and output. You will need to use a different provider for image or audio generation.

How is billing calculated?

Billing is based on real token usage. You pay $0.15 per 1 million input tokens and $0.50 per 1 million output tokens. Errors and refusals are free.