EN ▾
Get API key

Integrating Mistral Uncensored API with Python

Developers often seek a reliable way to integrate uncensored language models into their Python applications. This guide explains how to use our hosted endpoint with standard SDKs, focusing on stable text-in, text-out communication.

Server rack with glowing blue lights and Python code on holographic screen

Setting Up the Python Environment

To begin integrating our service, you need a Python environment with the appropriate libraries installed. The most common approach is to use the openai package, which provides a familiar interface for many developers. You can install this package using pip in your terminal or virtual environment. This library supports the standard parameters used by our endpoint, making the transition smooth for those already familiar with similar APIs.

Once the library is installed, you must configure your API key. Our service requires a valid key for authentication, which you receive immediately after signing up. You can store this key in an environment variable to keep it secure. This practice prevents accidental exposure of your credentials in your codebase or version control history.

Next, initialize the client object in your Python script. You will need to specify the base URL of our service, which is distinct from the default OpenAI endpoint. This ensures that your requests are routed correctly to our uncensored model. The base URL is https://api.mistraluncensored.cc/v1 .

Finally, verify your connection by making a simple request. A basic chat completion call can confirm that your setup is correct. If the request succeeds, you are ready to proceed with more complex interactions. This initial step ensures that your environment is properly configured for subsequent development tasks.

Authentication and Credit Management

Our API uses a prepaid credit system based on token usage. You do not need a monthly subscription or a credit card to start. Instead, you top up your account using cryptocurrency. The supported methods are USDT on the TRC20 network or USDC on the Base network. You can top up any whole amount between $20 and $500.

When you top up, you receive credit that is charged based on real token usage. Errors and refusals do not consume your credit, which helps you manage your budget effectively. Your paid credit never expires, so you can use it whenever you need it. This model is ideal for developers who want predictable costs without recurring fees.

Each new account starts with $0.50 of trial credit, allowing you to test the service without immediate payment. To add more credit, you must use the crypto payment methods mentioned above. No cards, PayPal, or bank transfers are accepted. This keeps the payment process simple and direct.

You can monitor your usage and balance through the dashboard. The API returns usage information in the final chunk of a streaming response. This allows you to track your token consumption in real-time. Understanding your credit balance helps you avoid unexpected interruptions in your application.

Making Chat Completion Requests

Our API serves a single uncensored open-weight text model with the ID uncensored. To make a request, you send a POST request to the /v1/chat/completions endpoint. The request body should follow the standard OpenAI chat completion format. This includes specifying the model ID, the user messages, and any optional parameters.

The model accepts text input and returns text output. You can send multiple messages in a conversation format to maintain context. The context window supports up to 100,000 tokens for both prompt and completion combined. This allows for long conversations or large documents to be processed in a single request.

You can customize the response using parameters like temperature, top_p, and stop sequences. These parameters allow you to control the creativity and format of the output. For example, setting the temperature to a higher value can produce more diverse responses. Conversely, a lower temperature yields more deterministic results.

Errors are handled gracefully, with specific HTTP status codes indicating the issue. A 401 error means your key is invalid, while a 402 error indicates insufficient credit. A 429 error signals that you have exceeded the rate limit of 300 requests per minute. Handling these errors ensures your application remains reliable.

Streaming and Function Calling

For real-time applications, our API supports streaming responses over Server-Sent Events (SSE). This allows you to receive tokens as they are generated, providing a smoother user experience. The usage information is included in the last chunk of the stream, so you can track consumption accurately.

Function calling is also supported, enabling your application to interact with external tools. You can define tools in your request, and the model will return structured data when appropriate. This feature is useful for building agents that can perform actions or fetch data.

JSON mode is available to ensure the model returns valid JSON output. This is particularly useful when parsing the response in your code. You can enforce this mode by setting the appropriate parameter in your request. This reduces the need for additional parsing logic in your application.

Parameters like seed and penalties allow for more control over the generation process. The seed parameter ensures reproducibility, which is helpful for testing. Penalties can be used to discourage certain tokens or patterns. These features give you fine-grained control over the model's behavior.

When Our API Is Not the Right Choice

While our API is excellent for uncensored text generation, it may not be the right choice for every project. If you need image, audio, or video generation, our service does not support these capabilities. You would need to integrate a separate service for those tasks.

Similarly, if you require embeddings for semantic search or document indexing, our API does not provide this feature. You would need to use a dedicated embedding model or service. Our service focuses solely on text-in, text-out interactions.

If you need fine-tuning capabilities to customize the model for your specific domain, our API does not offer this option. You would need to use a platform that supports fine-tuning. Our model is fixed, and you cannot train it on your own data.

Finally, if you need model routing to switch between different models based on the task, our API does not support this. We serve a single uncensored model. If you need to route requests to different models, you would need to implement that logic in your application or use a different service.

Addressing Community Concerns

Developers often discuss the broader implications of AI infrastructure and the role of European alternatives. Threads on r/BuyFromEU highlight concerns about Europe becoming an AI vassal state to US companies. Many users worry that US firms have more capital and will dominate the market, leaving European firms behind.

Some users point out that European companies like Mistral AI are making strides, but the investment levels in the US are mindboggling. This disparity makes it hard for smaller players to compete. Users also note that recruitment messages often come from the UK and US, with few from Europe, indicating a talent drain.

Another common topic is the use of AI by large companies. For example, Ecosia using Mistral AI instead of OpenAI is seen as a positive step for energy efficiency. Users appreciate when companies choose European alternatives that align with their values, even if the scale is smaller.

There is also discussion about the French Army using Mistral AI, which is seen as a key moment for European tech. Users hope this will lead to more support for European alternatives. However, some remain skeptical, noting that the money often ends up back in the US through chip purchases. These discussions show a strong desire for independent AI infrastructure.

Troubleshooting and Best Practices

To ensure a stable integration, always handle errors appropriately. Check for 401, 402, and 429 errors and implement retry logic if necessary. This helps your application recover from temporary issues without crashing. You can also log these errors for debugging purposes.

Monitor your token usage closely to avoid unexpected charges. Use the streaming response to track usage in real-time. This allows you to adjust your application's behavior if you are nearing your credit limit. You can also set up alerts for low balance.

Use environment variables for your API key to keep it secure. Avoid hardcoding the key in your source files. This practice reduces the risk of accidental exposure. You can also use a .env file to manage your configuration.

Test your integration thoroughly before deploying to production. Use the trial credit to experiment with different parameters and configurations. This helps you understand the model's behavior and optimize your requests. You can also test edge cases to ensure your application handles them gracefully.

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. No credit cards or PayPal are accepted.

What is the context window size?

The context window supports up to 100,000 tokens for both the prompt and the completion combined. This allows for long conversations or large documents to be processed in a single request.

Does the API support function calling?

Yes, the API supports function calling. You can define tools in your request, and the model will return structured data when appropriate. This is useful for building agents that can perform actions or fetch data.

What happens if I run out of credit?

If you run out of credit, you will receive a 402 error. You can top up your account using crypto to resume using the API. Errors and refusals do not consume your credit.