EN ▾
Get API key

Integrating an Uncensored Text API in Python

Developers often seek a minimal working bot that connects to an uncensored LLM API for text-in, text-out tasks. This article provides a step-by-step integration guide, including SDK settings and a tested checklist for verifying connectivity and output quality.

Developer integrating uncensored LLM API with Python script on a modern desk setup

Setting Up Your Python Environment

Before you can interact with the API, you need to prepare your development environment. The first step is to install the necessary Python packages. You will need the openai SDK, which is compatible with our API endpoint. Use pip to install the package in your virtual environment. This ensures that you have the correct version of the library that supports the chat completions endpoint.

Once the package is installed, you need to configure your API key. You can obtain this key by signing up on the platform. The key is shown immediately after signup, so you do not need to wait for an email. Store this key securely in your environment variables or a configuration file. Avoid hardcoding the key in your source code to prevent accidental exposure.

Next, initialize the OpenAI client in your Python script. Point the base URL to our API endpoint. This is important because the default base URL points to OpenAI's servers. By overriding this, you direct your requests to our uncensored model. Ensure that the API key is passed correctly in the client initialization.

Finally, test the connection by making a simple request. This step verifies that your environment is set up correctly. If the request succeeds, you are ready to proceed with more complex interactions. If it fails, check your key and the base URL for typos.

Configuring API Parameters

The API supports several parameters that allow you to control the behavior of the model. You can set the temperature to adjust the randomness of the output. A higher temperature results in more creative and varied responses, while a lower temperature produces more deterministic and focused outputs. This is useful for tasks where consistency is important.

Another important parameter is top_p, which controls the diversity of the output by filtering the most likely tokens. You can also set the seed to ensure reproducibility of your results. This is particularly useful for debugging and testing your application. By setting a specific seed, you can get the same response every time you run the code with the same input.

You can also define stop sequences to halt the generation at a specific point. This is useful for controlling the length of the response or for stopping the generation when a certain condition is met. Additionally, you can use penalties to discourage certain words or phrases in the output.

Finally, consider the context window size. Our API supports a context window of 100,000 tokens. This allows you to send large prompts and receive long responses. However, keep in mind that larger context windows may incur higher costs. Always monitor your token usage to stay within your budget.

Making Your First Request

Now that your environment is set up and parameters are configured, you can make your first request. Start with a simple prompt to verify that the API is working correctly. Send a message to the chat completions endpoint and wait for the response. The response will include the generated text, which you can then process or display.

It is important to handle the response correctly. The API returns a JSON object containing the generated text. You can extract this text and use it in your application. Make sure to handle any errors that may occur during the request. This includes network errors, authentication errors, and rate limit errors.

You can also enable streaming to receive the response in real-time. This is useful for applications where you want to display the text as it is being generated. Streaming allows you to provide a better user experience by showing the output incrementally. However, keep in mind that streaming may consume more resources.

Finally, test the API with different types of prompts. Try sending a simple question, a complex instruction, and a creative writing prompt. This will help you understand how the model responds to different inputs. You can also experiment with different parameters to see how they affect the output.

Handling Errors and Limits

When integrating with any API, it is essential to handle errors gracefully. Our API returns specific HTTP status codes to indicate the type of error. A 401 error indicates an invalid API key, while a 402 error indicates that you have no credit. A 429 error indicates that you have exceeded the rate limit.

You should implement error handling in your code to manage these scenarios. For example, if you receive a 402 error, you may need to prompt the user to top up their credit. If you receive a 429 error, you should implement a retry mechanism with exponential backoff. This prevents your application from overwhelming the API with too many requests.

It is also important to monitor your token usage. Our API charges based on the number of tokens used. You can track your usage by checking the response headers or by using the API's usage endpoint. This helps you stay within your budget and avoid unexpected charges.

Finally, be aware of the rate limits. Our API allows 300 requests per minute per key. If you exceed this limit, you will receive a 429 error. Plan your application's architecture to stay within this limit. You can also distribute your requests across multiple keys if needed.

When This Service Is Not the Right Choice

While our API is powerful for text generation, it may not be the right choice for every use case. If you need image, audio, or video generation, this service does not support those capabilities. It is strictly a text-in, text-out API. You will need to use a different provider for multimodal tasks.

Similarly, if you need embeddings for semantic search, our API does not provide this feature. You will need to use a separate embedding API to generate embeddings for your text data. This means you will need to integrate multiple services to build a complete application.

If you require fine-tuning of the model to customize its behavior for your specific domain, our API does not support this. You will need to use a provider that offers fine-tuning capabilities. This is an important consideration if you need the model to learn from your specific data.

Finally, if you need on-premises deployment for data privacy or compliance reasons, our hosted service may not fit your needs. You will need to look for a provider that allows you to deploy the model on your own infrastructure. Always evaluate your specific requirements before choosing a provider.

Addressing Community Questions

Developers often ask about the best uncensored LLM models for roleplay and creative writing. In threads on r/LocalLLM, users discuss various models for RP and ERP, noting that some models are better suited for specific types of content. They often test multiple models to find the one that best fits their needs. Our API provides a reliable option for these tasks, allowing you to generate diverse and engaging content.

Another common question is about finding an uncensored LLM that is not focused on character-based or roleplay scenarios. Users in r/AIToolTesting seek an unfiltered LLM that tells the truth without being politically correct. They want a model that can handle a wide range of topics without unnecessary restrictions. Our API meets this need by providing an uncensored model that can handle various types of input.

Users also inquire about the best uncensored LLM for coding and technical tasks. In r/LocalLLM, developers discuss the performance of different models for code generation. They look for models that can understand and generate code accurately. Our API supports this use case by providing a model that can handle technical prompts effectively.

Finally, users ask about the best uncensored LLM available at the moment. In r/GPT_jailbreaks, discussions revolve around the latest models and their capabilities. Our API offers a reliable and uncensored option for users who need a dependable text generation service. Always check the latest community discussions for the most current insights.

Testing and Verification Checklist

To ensure that your integration is working correctly, you should perform a series of tests. First, verify that you can connect to the API using your API key. Send a simple request and check that you receive a valid response. This confirms that your authentication is correct.

Next, test the different parameters. Send requests with different temperature, top_p, and seed values. Observe how the output changes with each parameter. This helps you understand how to configure the API for your specific needs. You can also test the stop sequences to ensure they work as expected.

Then, test the error handling. Simulate different error scenarios, such as an invalid key or a rate limit exceeded. Verify that your application handles these errors correctly and provides appropriate feedback to the user. This ensures that your application is reliable and user-friendly.

Finally, test the streaming functionality. Send a request with streaming enabled and verify that you receive the response in real-time. This is important for applications that require immediate feedback. By following this checklist, you can ensure that your integration is working correctly and efficiently.

Frequently asked questions

How do I get an API key?

You can obtain an API key by signing up on the platform. The key is shown immediately after signup, so you do not need to wait for an email. You can use this key to authenticate your requests.

What is the cost of using the API?

The API charges $0.15 per 1M input tokens and $0.50 per 1M output tokens. You can top up your credit using crypto, with a minimum top-up of $20. Errors and refusals are free.

Does the API support streaming?

Yes, the API supports streaming over SSE. This allows you to receive the response in real-time, which is useful for applications that require immediate feedback.

What are the rate limits?

The API allows 300 requests per minute per key. If you exceed this limit, you will receive a 429 error. You can distribute your requests across multiple keys if needed.