EN ▾

MiniCPM API: Use an OpenAI-Compatible Endpoint

If you searched for a MiniCPM API, here is the short version: this site is an independent, OpenAI-compatible text API, not the official MiniCPM service. It runs one open-weight model, tuned to answer without content refusals for lawful adult use, and you call it with any OpenAI SDK.

Updated

Key points

  • This is not the official MiniCPM API. It is a separate hosted service with one model, ID uncensored.
  • Change two things in any OpenAI client: base URL https://api.minicpm.top/v1 and the key.
  • Text only, 100,000-token context, streaming, tool calling and JSON mode are supported.
  • Price is $0.15 per 1M input tokens and $0.50 per 1M output tokens, prepaid.
A glowing model cube plugged into a server rack by a cable with data flowing, representing an OpenAI-compatible API

What this API is, and what it is not

People type this phrase into a search box for a few different reasons. Some want the official hosted service from the team behind the MiniCPM models. Some want to run the weights themselves and expose them over HTTP. Others just want a cheap chat endpoint that does not lecture them. It helps to be clear which of these you will find here.

This site is the third kind. It is a hosted API that follows the OpenAI chat completions format and serves a single open-weight model, run by an independent provider. The model is tuned to answer without content refusals for lawful adult use. It is not the official API of any model vendor, and it is not a router that forwards your request to different vendors. There is one model, and its ID is uncensored.

If you need a specific MiniCPM checkpoint, for example for a benchmark or because you depend on its exact behavior, this service will not give you that guarantee. In that case, run the weights yourself or use the vendor's own offering. If you need a text endpoint that works with the OpenAI tooling you already have, read on.

One hard rule applies to everything: no sexual content involving minors, ever.

Your first request in Python

Because the API speaks the OpenAI protocol, the official OpenAI Python package works unchanged. Install it with pip install openai, then point it at this site.

from openai import OpenAI

client = OpenAI(
    base_url="https://api.minicpm.top/v1",
    api_key="YOUR_KEY",
)

response = client.chat.completions.create(
    model="uncensored",
    messages=[
        {"role": "system", "content": "You are a concise technical assistant."},
        {"role": "user", "content": "Explain what a context window is in two sentences."},
    ],
    temperature=0.7,
)

print(response.choices[0].message.content)
print(response.usage)

Two values changed compared with a stock OpenAI script: base_url and api_key. The model name is uncensored. Everything else is the code you would write anyway.

The key comes from the API key page. New users can claim $0.50 of trial credit there with one click after signing up with Google or with email and password. It is valid for 7 days, one per person, and no card is needed.

The same call in Node and curl

For JavaScript, install the openai package and set the same two options.

import OpenAI from "openai";

const client = new OpenAI({
  baseURL: "https://api.minicpm.top/v1",
  apiKey: process.env.API_KEY,
});

const completion = await client.chat.completions.create({
  model: "uncensored",
  messages: [{ role: "user", content: "Give me three names for a small weather app." }],
});

console.log(completion.choices[0].message.content);

And the raw HTTP version, which is handy for debugging because it shows exactly what goes over the wire:

curl https://api.minicpm.top/v1/chat/completions \
  -H "Authorization: Bearer YOUR_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "uncensored",
    "messages": [{"role": "user", "content": "Give me three names for a small weather app."}],
    "max_tokens": 200
  }'

Two methods exist: POST /v1/chat/completions and GET /v1/models. There is no embeddings route, no image route and no audio route. If your project needs those, pair this API with another service for that part.

Streaming, tools and JSON mode

Most of what developers reach for beyond a basic call is available.

Streaming

Set stream: true and read server-sent events. Token usage arrives at the end of the stream. One detail matters for concurrency: a streamed request holds its slot until the stream finishes, so if you abandon a stream without closing it, you keep a slot occupied.

from openai import OpenAI

client = OpenAI(base_url="https://api.minicpm.top/v1", api_key="YOUR_KEY")

stream = client.chat.completions.create(
    model="uncensored",
    messages=[{"role": "user", "content": "Write a four-line poem about compilers."}],
    stream=True,
)
for chunk in stream:
    if chunk.choices and chunk.choices[0].delta.content:
        print(chunk.choices[0].delta.content, end="", flush=True)

Tool calling

Pass tools and optionally tool_choice. When the model decides to call a function, you run it and send the result back as a message with role: "tool". Streamed tool_calls work too.

JSON mode

Add response_format: {"type": "json_object"} and say in the prompt that you want JSON. Parsing still deserves a try/except in production code, as with any model.

Sampling controls such as temperature, top_p, stop, seed and the frequency and presence penalties are passed through to the model.

Limits you should design around

The context window is 100,000 tokens, counting prompt and completion together. You do not need to set max_tokens; the completion can use whatever remains. The maximum request body is 8 MB.

Key typeConcurrent requestsRequests per minute
Trial260
Full8300

Going over returns HTTP 429. The error code is rate_limited for the per-minute limit and concurrency for too many simultaneous requests. A 429 with a Retry-After: 5 header signals temporary overload. A simple retry loop that sleeps for the header value handles all three in most apps.

Every response carries X-Request-Id, X-Balance-USD, X-RateLimit-Limit-Requests and X-RateLimit-Limit-Concurrency. Log the request ID; it makes support conversations much shorter. The docs page has the full quickstart, and the support page is the place to ask when something looks wrong.

What a real workload costs

You pay $0.15 per 1M input tokens and $0.50 per 1M output tokens. Credit is prepaid, never expires, and failed or refused requests are not charged.

Take a support-style chat app that sends about 2,000 input tokens and gets about 500 output tokens per request, and handles 10,000 requests.

  • Input: 10,000 x 2,000 = 20,000,000 tokens = 20M x $0.15 = $3.00
  • Output: 10,000 x 500 = 5,000,000 tokens = 5M x $0.50 = $2.50
  • Total: $5.50

Output tokens cost more than three times as much as input tokens, so tight prompts matter less than keeping replies the length you actually need. Top-ups are any whole amount from $20 to $500, with +5% bonus from $50, +10% from $100 and +15% from $200. You can pay by crypto (USDT on TRC20, USDC on Base). Details are on the pricing page.

Prompts are not used for training.

Choosing between this and running MiniCPM yourself

It also helps to be plain about what you give up with any hosted API. Your prompts leave your machine and travel to the provider. Prompts here are not used for training, but if your data is regulated or confidential in a way that forbids any third party, a local model is the safer route. And with a single fixed model, you cannot pick a different size or quantization to trade speed for quality.

Self-hosting is a fair choice and sometimes the better one. If you need a particular checkpoint, want full control over weights, or process data that must never leave your own machine, run it locally and skip any hosted service. The cost is hardware, setup time and keeping the stack updated.

There is a cost angle too. A GPU that can run a capable model sits idle most of the day for many projects, while the hosted endpoint charges only for the tokens you use. For a side project that sends a few thousand requests a month, the bill is a few cents to a few dollars.

A hosted endpoint makes sense when you want to write the application, not operate GPUs. You get an HTTP address, a key and pay-as-you-go billing, and your existing OpenAI-based code keeps working. Switching later in either direction is cheap, because the client code only knows a base URL and a model name.

Handling errors in production code

A script that works once in a terminal is not yet a service. Three habits make the difference.

Retry only what is worth retrying. A 429 is a signal to wait. If the response has Retry-After: 5, sleep five seconds. If it carries rate_limited, you are sending too many requests per minute, and the fix is a queue or a slower loop. If it carries concurrency, you have too many calls in flight at once, and the fix is a semaphore sized to your key: 2 for a trial key, 8 for a full one.

import time
from openai import OpenAI, RateLimitError

client = OpenAI(base_url="https://api.minicpm.top/v1", api_key="YOUR_KEY")

def chat(messages, tries=4):
    for attempt in range(tries):
        try:
            r = client.chat.completions.create(model="uncensored", messages=messages)
            return r.choices[0].message.content
        except RateLimitError:
            time.sleep(5 * (attempt + 1))
    raise RuntimeError("still rate limited after retries")

Do not retry a 4xx error other than 429 blindly; a malformed body will fail the same way every time. And log the X-Request-Id header on every failure.

Finally, watch spend from inside the app. The X-Balance-USD header on each response lets you raise an alert before the credit runs out, so a production job never stops halfway through a batch.

Questions and answers

Is this the official MiniCPM API?

No. It is an independent, OpenAI-compatible service that runs one open-weight model under the ID uncensored. It is not affiliated with any model vendor.

Can I send images or audio?

No. The API is text only. There is no image, audio or video input or generation, and no embeddings.

Which SDK should I use?

Any OpenAI SDK works. Set the base URL to https://api.minicpm.top/v1, use your key and the model ID uncensored.

Is there a free trial?

New users can claim $0.50 of trial credit with one click on the API key page. It lasts 7 days and needs no card.

Your key is one form away

Create an account, copy the key, change the base URL. That is the whole setup.

Get API key