Integrating Uncensored Local AI with Python Scripts
Developers often need to integrate large language models into custom Python applications without relying on heavy user interfaces. This guide walks you through configuring the SDK, managing endpoints, and handling text-in/text-out responses for smooth automation.

Setting Up the Python Environment
Before you can send requests to our API, you need to prepare your Python environment. The most common approach is to use the standard openai Python package, as our service is fully compatible with the OpenAI chat completions format. You can install this package using pip in your terminal or virtual environment. This ensures that your script uses the same client library that many developers are already familiar with, reducing the learning curve for integration.
Once installed, you will need to configure your client object with the correct base URL. Instead of pointing to the default OpenAI endpoint, you must direct your client to https://api.uncensoredlocalai.com/v1. This ensures that all requests are routed to our uncensored model rather than any other provider. You should also set your API key in the environment variables or directly in your script for authentication.
It is important to note that our API supports only text input and text output. You do not need to configure image or audio generators, as those features are not present in this service. Keeping your environment focused on text processing will help you avoid unnecessary complexity when building your automation tools. The model ID you will use for all requests is simply uncensored.
By setting up your environment correctly from the start, you ensure that your scripts can communicate effectively with the API. This foundational step is important for any developer looking to automate text generation tasks using Python. The simplicity of the setup allows you to focus on the logic of your application rather than wrestling with complex configuration files.
Configuring Endpoints and Parameters
Our API exposes three main endpoints for you to interact with. The primary endpoint for generating text is POST /v1/chat/completions. This is where you will send your prompts and receive responses. You can also use POST /v1/responses for alternative response formats, though the chat completions endpoint is the standard for most use cases. Finally, GET /v1/models allows you to verify the available models, though in our case, there is only one uncensored model available.
When making requests, you can utilize various parameters to control the output. These include temperature for randomness, top_p for nucleus sampling, and stop sequences to halt generation. You can also set a seed for reproducible results. These parameters give you fine-grained control over how the model generates text, allowing you to tailor the output to your specific needs.
It is important to understand that our API does not support embeddings, image generation, audio processing, or video generation. If your project requires these features, you will need to look elsewhere or combine our text API with other services. The focus here is strictly on text-in and text-out capabilities, which are sufficient for many automation workflows.
By configuring your endpoints and parameters correctly, you can ensure that your Python scripts interact with the API efficiently. This setup allows you to send requests and receive responses in a predictable manner, which is essential for building reliable automation tools. The flexibility of the parameters means you can experiment with different settings to find the best output for your application.
Handling Streaming and JSON Responses
One of the powerful features of our API is support for streaming responses over Server-Sent Events (SSE). This allows you to receive text chunks as they are generated, which can improve the user experience in real-time applications. In your Python script, you can iterate over the stream to process each chunk of text as it arrives. This is particularly useful for long responses where you want to display progress or update the interface dynamically.
Additionally, our API supports JSON mode, which ensures that the output is valid JSON. This is incredibly useful for automation workflows where you need to parse the response programmatically. By enabling JSON mode, you can guarantee that the model returns structured data, making it easier to integrate with other parts of your application. This feature reduces the need for additional parsing logic in your code.
When handling streaming responses, remember that usage information is included in the last chunk. This allows you to track token consumption in real-time, which is helpful for monitoring your prepaid credit usage. You can also use the usage data to optimize your scripts for cost efficiency by minimizing unnecessary requests or optimizing prompt lengths.
By using streaming and JSON mode, you can build more reliable and efficient Python scripts. These features allow you to handle large volumes of text data effectively, ensuring that your automation workflows run smoothly and reliably. The combination of real-time updates and structured output makes our API a versatile tool for developers.
Managing Billing and Credits
Our API operates on a prepaid credit system, meaning you pay for what you use without any monthly subscriptions. The pricing is straightforward: $0.15 per 1 million input tokens and $0.50 per 1 million output tokens. Errors and refusals are free, so you only pay for successful token generation. This model allows you to budget your spending based on actual usage, which is ideal for indie builders and small teams.
To add credit to your account, you can use cryptocurrency. We accept USDT on the TRC20 network or USDC on the Base network. You can top up with any whole amount between $20 and $500. If you top up with $50 or more, you may receive a bonus credit ranging from 5% to 15%. This incentivizes larger top-ups and provides extra value for your investment.
It is important to note that we do not accept credit cards, PayPal, or bank transfers. All payments must be made via crypto. This method ensures fast transactions and low fees, but it does require you to have a crypto wallet. The prepaid credit never expires, so you can top up when convenient and use it over time.
Understanding the billing structure helps you plan your development budget effectively. By tracking your token usage and managing your credits wisely, you can ensure that your automation scripts run without interruption. The transparent pricing model allows you to predict costs accurately, making it easier to scale your projects.
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 processing, or video creation, you will need to look for a different service. Our API is strictly text-in and text-out, so it cannot handle multimedia content directly.
Similarly, if you need advanced features like embeddings for semantic search, OCR for text extraction from images, or fine-tuning to customize the model for your specific domain, our API does not support these capabilities. In such cases, you might need to combine our text API with other tools or choose a more comprehensive platform.
Additionally, if you require high availability guarantees or specific compliance certifications like SOC2 or HIPAA, our API does not currently offer these. We are an independent service focused on providing uncensored text generation without the overhead of enterprise-grade SLAs. For projects with strict regulatory requirements, you may need to evaluate other providers.
Finally, if you are looking for a free unlimited tier, our API is not the best fit. We operate on a prepaid credit model, so you will always need to fund your account. However, new accounts receive $0.50 of trial credit, allowing you to test the service before committing. Assessing these limitations helps you determine if our API aligns with your project's specific needs.
Addressing Community Questions on Reddit
Developers often discuss integrating local AI APIs into various tools on Reddit. For instance, users have asked about connecting local AI to resume tailoring tools or story chat applications. In these contexts, the ability to automate text generation without a complex UI is a major benefit. Our API allows you to feed prompts into these tools programmatically, enhancing their functionality.
Another common question involves using local AI for grammar checking in LibreOffice. Users want to know if they can use an API to fix grammar and spelling errors without relying on subscription-based services. Our uncensored model can be configured to act as a grammar checker, providing a free and flexible alternative to traditional tools.
Some users have also explored using mobile devices like the iPhone 17 Pro as a local AI API. While this approach can be slow, it offers a free option for those with compatible hardware. Our API provides a more reliable and faster alternative for those who do not want to rely on local device constraints.
By addressing these community questions, we can see how our API fits into diverse workflows. Whether it is for resume matching, story generation, or grammar checking, our text-only API offers a versatile solution for developers looking to automate text tasks. The ability to integrate with various tools makes it a valuable addition to any developer's toolkit.
Troubleshooting and Error Handling
When integrating with our API, it is important to handle errors gracefully. Our API returns specific HTTP status codes to indicate different issues. A 401 error means your API key is invalid, so you should check your credentials. A 402 error indicates that you have no credit left, which means you need to top up your account. A 429 error signals that you have hit the rate limit of 300 requests per minute per key.
To avoid hitting the rate limit, you can implement exponential backoff in your Python scripts. This technique involves waiting for increasing intervals between requests if you receive a 429 error. This helps prevent overwhelming the API and ensures that your scripts run smoothly even during peak usage times.
Additionally, you should handle cases where the model refuses a request due to the hard content limit. Our API refuses requests involving sexual content with minors, so you may need to adjust your prompts if you encounter refusals. Understanding these limits helps you design your automation workflows more effectively.
By implementing reliable error handling, you can ensure that your Python scripts remain reliable and efficient. This includes checking for valid keys, monitoring credit balances, and managing rate limits. Proper error handling is essential for building production-ready applications that can handle unexpected issues without crashing.
Frequently asked questions
How do I set up the Python SDK for the uncensored API?
Install the openai package and configure the base URL to https://api.uncensoredlocalai.com/v1. Use the model ID 'uncensored' for all requests.
What payment methods are accepted for topping up credit?
We accept only crypto: USDT on TRC20 or USDC on Base. Credit cards, PayPal, and bank transfers are not supported.
Does the API support image or audio generation?
No, the API is text-in and text-out only. It does not support embeddings, images, audio, video, or OCR.
What happens if I run out of credit?
You will receive a 402 error. You can top up with crypto to add more credit, which never expires.