EN ▾
Get API key

Integrating an Uncensored API with Python

Developers often need a straightforward way to connect to an uncensored language model without dealing with complex infrastructure. This guide walks you through configuring a Python client to interact with our API endpoints using standard libraries. We focus on practical steps for authentication, handling tokens, and managing streaming responses in your local environment.

Developer workspace showing Python code for API integration

Setting Up Your Python Environment

Before you can send requests to our API, you need to prepare your Python environment. Start by installing the requests library, which is the standard tool for making HTTP calls in Python. You can install it using pip in your terminal. This library handles the underlying HTTP connections and headers for you, making it easier to focus on the logic of your application.

Next, create a new Python script or Jupyter notebook where you will write your integration code. Import the requests module at the top of your file. You will also need to store your API key securely. Avoid hardcoding the key directly in your script if you plan to share it. Instead, use environment variables or a configuration file to keep your credentials safe.

Define the base URL for our API as a constant in your script. The base URL is https://api.abliterated.cc/v1. This URL is the foundation for all your API calls. By defining it once, you can easily change it if the service updates its domain in the future. Ensure that your script uses this base URL for every request you make.

Finally, test your connection by sending a simple GET request to the /v1/models endpoint. This endpoint returns information about the available models. If you receive a successful response, your environment is set up correctly. If you encounter an error, check your internet connection and ensure that your API key is valid. This initial step confirms that your Python script can communicate with our servers.

Configuring Authentication and Headers

Authentication is the first step in every API request. Our API uses a simple Bearer token scheme. You need to include your API key in the Authorization header of every POST request. The format is Authorization: Bearer YOUR_API_KEY. Make sure to replace YOUR_API_KEY with the key you received during signup. This key is shown immediately after you create your account.

When you sign up, you can use Google or an email and password combination. The key is generated right away, so you can start using it without delay. Keep this key secure, as it provides access to your prepaid credit. If you lose your key, you may need to generate a new one from your dashboard. Never share your key publicly, as anyone with the key can use your credit.

Include the Content-Type header set to application/json in your requests. This tells the server that you are sending JSON data. Our API expects JSON formatted bodies for both the /v1/chat/completions and /v1/responses endpoints. Failing to set this header correctly may result in errors when you try to send messages.

Test your authentication by sending a request with an invalid key. The server should return a 401 error, indicating an invalid key. This helps you verify that your authentication logic is working. If you send a request with a valid key but no credit, you will receive a 402 error. These error codes help you troubleshoot issues quickly and ensure that your script handles authentication correctly.

Sending Requests and Handling Responses

Once your environment is set up, you can start sending requests. Use the POST method to send data to the /v1/chat/completions endpoint. The request body should be a JSON object containing the model, messages, and optional parameters like temperature or top_p. The model ID to use is uncensored. This model does not refuse lawful adult, fictional, or controversial topics.

The messages field should be a list of dictionaries, each with a role and content. The role can be system, user, or assistant. The content is the text you want to send. Our API supports a context window of 100,000 tokens, which includes both the prompt and the completion. This allows for long conversations or large documents.

When you receive a response, parse the JSON data to extract the generated text. The response will include the choices field, which contains the model's output. You can access the text using the message object within the choices. Handle any errors that might occur during the request, such as network timeouts or server errors.

Remember that our API is text-in, text-out. It does not support embeddings, image generation, audio, or video. If you need those features, you will need to use a different service. For now, focus on getting the text output from the model. You can then process this text in your Python script as needed for your application.

Implementing Streaming Responses

Streaming is a useful feature for real-time applications. Our API supports streaming over Server-Sent Events (SSE). To enable streaming, set the stream parameter to true in your request body. When you send a request with streaming enabled, the server will send partial responses as the model generates text.

In Python, you can handle streaming by reading the response line by line. Each line starts with data: and contains a JSON object. Parse each line to extract the text chunk. This allows you to display the output to the user as it is generated, rather than waiting for the entire response. This is particularly useful for chat interfaces or long-form content generation.

The last chunk of a streaming response includes usage information, such as the number of tokens used. You can use this information to track your credit usage. Our API charges $0.15 per million input tokens and $0.50 per million output tokens. Streaming does not change the pricing; you are charged for the total tokens used in the conversation.

Handle the end of the stream by checking for the data: [DONE] message. This indicates that the model has finished generating text. You can then close the connection and process the final output. Streaming requires more complex error handling than non-streaming requests, so ensure your code is reliable.

Managing Tokens and Credit

Understanding token usage is important for managing your budget. Our API charges based on the number of tokens in the input and output. Input tokens are charged at $0.15 per million, and output tokens are charged at $0.50 per million. You can calculate the cost by dividing the token count by one million and multiplying by the respective price.

You start with $0.50 of trial credit when you create a new account. No credit card is needed to start. You can top up your credit using crypto, specifically USDT on TRC20 or USDC on Base. The minimum top-up amount is $20, and the maximum is $500. You can also receive bonus credit when you top up from $50.

Errors and refusals are free, so you do not lose credit if a request fails. However, you will receive a 402 error if you run out of credit. Make sure to monitor your usage to avoid unexpected interruptions. You can check your credit balance in your dashboard to plan your top-ups.

Use the seed parameter to get reproducible results. This is useful for testing and debugging. You can also set temperature and top_p to control the creativity of the model. Lower values make the output more deterministic, while higher values introduce more randomness. Adjust these parameters based on your application's needs.

When This API Is Not the Right Choice

While our API is powerful for text generation, it may not be the right choice for every project. If you need image, audio, or video generation, our API does not support these features. You will need to find a different service that offers multimodal capabilities. Similarly, if you need embeddings for vector search, our API does not provide this functionality.

Our API is focused on text-only interactions. If your application requires OCR, fine-tuning, or model routing, you will need to look elsewhere. The model we offer is an uncensored open-weight text model. It does not support the same range of specialized tasks as larger, more complex models.

Additionally, if you need a service with a strict SLA or certifications like SOC2 or HIPAA, our API may not meet those requirements. We do not claim these certifications. If you are building a mission-critical application that requires high availability and data privacy guarantees, you should evaluate other providers.

Finally, if you prefer a subscription-based model with monthly fees, our prepaid credit system might not suit your budgeting needs. We offer a pay-as-you-go model with no monthly fees. This is ideal for developers who want flexibility and control over their spending. However, it may not be suitable for enterprises with fixed IT budgets.

Addressing Common Developer Questions

Developers often ask about the best uncensored models for roleplay or creative writing. Our API provides an uncensored model that does not refuse lawful adult or fictional topics. This makes it suitable for roleplay applications where you want the model to be less restrictive. You can use the temperature parameter to adjust the creativity of the responses.

Another common question is how to handle errors in your script. Our API returns specific error codes, such as 401 for invalid keys and 402 for no credit. You can handle these errors in your Python code to provide a better user experience. For example, you can prompt the user to top up their credit if they receive a 402 error.

Users also ask about the context window size. Our API supports a context window of 100,000 tokens. This is sufficient for long conversations or large documents. If you need a larger context window, you may need to look at other providers. However, for most applications, 100,000 tokens is more than enough.

Finally, developers often wonder about the pricing structure. Our API charges per token, with no monthly fees. This is transparent and easy to understand. You can calculate the cost of your requests based on the number of tokens used. This makes it easy to budget for your API usage.

Frequently asked questions

How do I authenticate with the API?

Include your API key in the Authorization header as a Bearer token. You can get your key from the dashboard after signing up with Google or email.

What is the context window size?

The context window is 100,000 tokens, including both the prompt and the completion. This allows for long conversations and large inputs.

How is pricing calculated?

You are charged $0.15 per million input tokens and $0.50 per million output tokens. Errors and refusals are free.

Can I stream responses?

Yes, set the stream parameter to true to receive Server-Sent Events. The last chunk includes usage information for tracking token counts.