Integrating MiniCPM Uncensored API with Python SDK
Developers often seek a straightforward way to integrate an uncensored text model into their Python applications without complex overhead. This guide provides a tested checklist for connecting to the endpoint, configuring the SDK, and executing your first request. You will learn how to handle authentication, manage parameters, and interpret responses efficiently.

Understanding the API Structure
The MiniCPM uncensored API is designed to be compatible with standard chat-completion interfaces. This means you can use familiar libraries and structures to interact with the model. The service serves a single uncensored open-weight text model, identified by the model ID uncensored. It processes text input and returns text output, making it ideal for pure text generation tasks.
The base URL for all endpoints is https://api.minicpm.cc/v1. You will primarily interact with the POST /v1/chat/completions endpoint for generating responses. There is also a POST /v1/responses endpoint for newer response formats and a GET /v1/models endpoint to verify available models. The API does not support embeddings, image generation, audio, video, OCR, fine-tuning, or model routing.
The context window is set to 100,000 tokens, which includes both the prompt and the completion. This allows for substantial input data and long-form generation. The model is uncensored, meaning it does not refuse lawful adult, fictional, security-research, or controversial topics. However, it enforces a hard content limit regarding sexual content involving minors, which will be refused.
When integrating, ensure your application handles the specific parameters supported by this service. You can control the output using parameters such as temperature, top_p, stop sequences, seed, and various penalties. The API also supports streaming over Server-Sent Events (SSE), allowing you to receive usage information in the last chunk of the stream. This structure makes it easy to build responsive applications that provide real-time feedback to users.
Authentication and Key Management
To start using the API, you need an API key. You can sign up by continuing with Google or using an email and password. Once registered, your API key is shown immediately, so make sure to copy it securely. The key is required for all requests to the API. If you send an invalid key, you will receive a 401 error. If you have no credit, you will receive a 402 error.
The pricing model is prepaid credit charged by real token usage. There is no monthly subscription or fee. Paid credit never expires, so you can use it whenever you need. The cost is $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 actual token consumption.
To add credit, you must use cryptocurrency. The accepted methods are 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 $50 or more, you receive bonus credit ranging from +5% to +15%. There are no options for credit cards, PayPal, or bank transfers.
Every new account receives $0.50 of trial credit, so you do not need to add a card to start testing. You can monitor your usage and balance through the dashboard. If you exceed the rate limit of 300 requests per minute per key, you will receive a 429 error. Plan your requests accordingly to avoid interruptions in your application.
Setting Up the Python Environment
Before writing code, ensure your Python environment is ready. You will need Python 3.8 or higher installed on your system. It is recommended to use a virtual environment to manage dependencies. This keeps your project isolated and prevents conflicts with other packages. Create a new directory for your project and activate the virtual environment.
Install the required library using pip. The standard library for OpenAI-compatible APIs is widely used and well-documented. Run pip install openai to install the client. This library provides the necessary tools to connect to the MiniCPM API. It handles the HTTP requests, authentication, and response parsing automatically.
Configure your API key in your environment variables or a secure configuration file. Never hardcode the key in your source code, especially if you plan to share your project. Use a library like python-dotenv to load the key from a .env file. This practice enhances security and makes it easy to switch keys without changing code.
Initialize the client in your Python script. Set the base URL to https://api.minicpm.cc/v1 and provide your API key. The client will use this configuration to send requests to the correct endpoint. You can now proceed to make your first API call. The library supports both synchronous and asynchronous operations, allowing you to choose the best approach for your application.
Making Your First Request
Now that your environment is set up, you can make your first request. Use the chat.completions.create method to send a message to the model. Specify the model ID as uncensored. Provide a list of messages containing the user prompt. The API expects a structured input format with roles such as user and assistant.
Here is a simple example of a request. You can send a basic question and receive a response. The API will process the input and return the generated text. You can access the response content from the result object. This basic interaction demonstrates the core functionality of the API.
You can also explore advanced features like function calling. Define tools or functions that the model can use. The API will return a request to call a specific function with arguments. You can then execute the function and send the result back to the model. This enables complex workflows and integrations with external services.
JSON mode is another powerful feature. You can force the model to output valid JSON. This is useful for structured data extraction or generating configuration files. Set the response format to JSON in your request. The model will adhere to the schema you provide, ensuring consistent output. This feature is particularly valuable for applications that require reliable data structures.
Handling Streaming Responses
For applications that require real-time feedback, streaming is essential. The API supports streaming over Server-Sent Events (SSE). When you enable streaming, the response is sent in chunks. This allows you to display text as it is generated, improving the user experience.
Enable streaming in your request by setting the stream parameter to true. The client will yield chunks of text as they arrive. You can accumulate these chunks to build the full response. The last chunk typically contains usage information, such as token counts. This allows you to track costs and performance accurately.
Handle errors gracefully during streaming. Network issues or rate limits can interrupt the stream. Use try-except blocks to catch exceptions and handle them appropriately. You can retry the request or notify the user of the issue. Streaming adds complexity to error handling, so test your implementation thoroughly.
Consider the impact of streaming on your application's architecture. You may need to manage state and updates differently. Ensure your UI updates smoothly without lag. Streaming is ideal for chat interfaces and real-time data feeds. It provides a more interactive and engaging experience for users.
When This API Is Not the Right Choice
While the MiniCPM API is powerful for text generation, it may not be the right choice for every use case. It is a text-only API, so it does not support image, audio, or video generation. If your application requires multimodal capabilities, you will need to integrate additional services.
The API also does not offer embeddings, OCR, or fine-tuning. If you need to build a search engine or process documents, you will need separate tools for these tasks. The model routing feature is also absent, meaning you cannot switch between different models dynamically.
For applications requiring high availability or specific compliance standards, consider the limitations. The service does not claim SLA percentages, certifications like SOC2 or HIPAA, or on-prem deployment options. If your business requires strict data retention policies or guaranteed uptime, you may need to evaluate other options.
Additionally, the payment method is restricted to cryptocurrency. If your team prefers traditional payment methods like credit cards or bank transfers, this service might not fit your workflow. The prepaid credit model also means you must manage your budget carefully. Ensure these factors align with your project requirements before integrating.
Addressing Community Questions
Developers in communities like r/LocalLLaMA often discuss the capabilities of MiniCPM models. Threads frequently mention the efficiency of smaller models and their performance on specific hardware. Users share experiences with running models on devices like the Orange Pi AIPro, highlighting the importance of inference engines.
Some discussions focus on the multimodal capabilities of newer MiniCPM versions, such as vision and speech integration. While our API is text-only, the underlying model architecture is related. Users appreciate the model's ability to handle complex tasks with fewer parameters. This efficiency is a key advantage for resource-constrained environments.
Another common topic is the comparison between different model sizes and quantizations. Users debate the trade-offs between F16 and Q8_0 formats. While our API serves a specific uncensored version, understanding these trade-offs helps developers choose the right approach for their local deployments. The community values transparency and real-world performance data.
Finally, users often ask about the ease of integration and the quality of documentation. Our API provides a straightforward interface compatible with standard libraries. This reduces the learning curve for developers familiar with OpenAI-style APIs. By addressing these community concerns, we aim to provide a reliable and accessible tool for text generation.
Frequently asked questions
How do I get an API key?
Sign up with Google or email/password on the site. Your API key is shown immediately after registration. Use this key for authentication in your requests.
What is the cost of using the API?
The cost is $0.15 per 1 million input tokens and $0.50 per 1 million output tokens. You pay only for real token usage, and errors are free. Credit is prepaid and never expires.
Can I use credit cards to pay?
No, payments are crypto only. You can top up with USDT on TRC20 or USDC on Base. The minimum top-up is $20, and the maximum is $500.
Does the API support streaming?
Yes, the API supports streaming over Server-Sent Events (SSE). You can receive responses in chunks, with usage information provided in the last chunk. This is ideal for real-time applications.