Check that text is enough for you
Omni-style models take in speech, pictures and text, and some answer back with a voice. If that is the feature you need, a text endpoint will not replace it. Be sure before you spend time on setup.
This service covers the text half of such a stack. It exposes POST /v1/chat/completions and GET /v1/models, serves one open-weight model from an independent provider, and is tuned to answer without content refusals for lawful adult use. It is not the official API of any model vendor. People often combine it with separate speech-to-text and text-to-speech tools: transcribe the audio elsewhere, send the text here, and voice the answer with a speech tool of your choice. The language model in the middle does not care where the words came from.
A voice assistant built this way has three stages: speech to text, this API for the reply, and text to speech. Each stage adds delay, and the middle one is the only part you pay for here. Streaming helps, because you can start speaking the first sentence while the rest is still being generated.
If that matches what you are building, the rest of this page is a quick start.
Step 1: get a key
Sign up with Google, or with email and password, on the API key page. Once you are in, one click claims $0.50 of trial credit. It is one per person, valid for 7 days, and no card is involved.
The trial key has limits of 2 concurrent requests and 60 requests per minute. Those are more than enough for testing from a single script. Keep the key out of source control: put it in an environment variable, and never ship it inside a browser or mobile app, where anyone can read it. If your app has a front end, call this API from your own server and let the front end talk to your server instead. That also gives you one place to add per-user limits, so a single visitor cannot drain the balance. Rotate the key if you ever suspect it leaked.
export API_KEY="YOUR_KEY"
export API_BASE="https://api.minicpm.top/v1"
# model ID for every request below: uncensored
Step 2: send the first request
Authentication is a standard bearer header: Authorization: Bearer <key>. The smallest useful request has a model and one message.
curl https://api.minicpm.top/v1/chat/completions \
-H "Authorization: Bearer $API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "uncensored",
"messages": [{"role": "user", "content": "Reply with the single word: ready"}]
}'
The response is a JSON object with a choices array. The text is at choices[0].message.content, and a usage object reports prompt and completion tokens. Look at the response headers as well. X-Request-Id identifies the call, and X-Balance-USD shows what is left in your account.
If you get 401, the key is wrong or has stray whitespace. If you get a 429 on the very first call, read the error code: rate_limited means too many requests in a minute, and concurrency means too many at once.
Step 3: the same thing in Python and Node
Any OpenAI SDK works once you change the base URL and key. Python:
import os
from openai import OpenAI
client = OpenAI(base_url="https://api.minicpm.top/v1", api_key=os.environ["API_KEY"])
out = client.chat.completions.create(
model="uncensored",
messages=[{"role": "user", "content": "Reply with the single word: ready"}],
)
print(out.choices[0].message.content)
Node:
import OpenAI from "openai";
const client = new OpenAI({
baseURL: "https://api.minicpm.top/v1",
apiKey: process.env.API_KEY,
});
const out = await client.chat.completions.create({
model: "uncensored",
messages: [{ role: "user", content: "Reply with the single word: ready" }],
});
console.log(out.choices[0].message.content);
Prompt format basics
The prompt is a list of messages. Each has a role and content. Three roles cover almost everything. A fourth, tool, is used only when you run function calls and send results back.
system: standing instructions, such as tone, format and persona. Put it first.user: what the person says.assistant: earlier model replies, which you resend so the model has the conversation.
The API is stateless. It does not remember the last call, so a multi-turn chat means appending each new user message and each reply to the list yourself and sending the whole list again. The window is 100,000 tokens for prompt and completion together, which is a lot of conversation, but input tokens are billed on every call, so trim history you no longer need.
from openai import OpenAI
client = OpenAI(base_url="https://api.minicpm.top/v1", api_key="YOUR_KEY")
history = [{"role": "system", "content": "Answer in one short paragraph."}]
def ask(text):
history.append({"role": "user", "content": text})
r = client.chat.completions.create(model="uncensored", messages=history)
reply = r.choices[0].message.content
history.append({"role": "assistant", "content": reply})
return reply
Sampling settings you may know from other APIs are passed through: temperature, top_p, stop, seed and the penalties. Lower the temperature for extraction and code, raise it for fiction. Setting max_tokens is optional, since the completion can use the rest of the window.
Step 4: stream the answer
For a chat interface you want words as they arrive. Add stream: true; the server sends events over SSE and gives usage numbers at the end.
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": "List three uses for a hash map."}],
stream=True,
)
for part in stream:
if part.choices and part.choices[0].delta.content:
print(part.choices[0].delta.content, end="", flush=True)
Each event carries a small piece of the reply in delta.content. The loop above prints pieces as they arrive and ignores events with no text, such as the final one that carries usage. In a web app you would forward each piece to the browser; in a terminal tool you print it. Either way the total cost is the same as a non-streamed call with the same lengths.
Remember that a stream keeps its concurrency slot until it ends. If a user closes the tab, cancel the request on your side so the slot is released. Tool calling and JSON mode (response_format with json_object) are available once the basics work; the docs show both.
How far the trial credit goes
Pricing is $0.15 per 1M input tokens and $0.50 per 1M output tokens. Consider a typical small request with 1,000 input tokens and 300 output tokens.
- Input: 1,000 / 1,000,000 x $0.15 = $0.00015
- Output: 300 / 1,000,000 x $0.50 = $0.00015
- Per request: $0.0003
Divide the $0.50 trial credit by $0.0003 and you get about 1,666 such requests. At the trial rate limit of 60 per minute, that is a little under half an hour of nonstop calls, so there is plenty of room to test properly. A prompt that carries a long document costs more: 20,000 input tokens and 300 output tokens come to 20,000 / 1,000,000 x $0.15 = $0.003 plus $0.00015, which is $0.00315 per request. Longer prompts use the credit faster, so measure with your real prompts and check X-Balance-USD after a few calls.
When you move on, top up any whole amount from $20 to $500 with crypto, with bonuses of +5% from $50, +10% from $100 and +15% from $200. Failed or refused requests are not charged, credit never expires, and there is no subscription. Everything is on the pricing page.
Common first-request mistakes
Most failed first calls come from a short list of causes, and each one is quick to fix.
- Wrong path. The base URL already ends in
/v1. If your client adds/v1again you will see a 404. With the OpenAI SDKs, set only the base URL and let the library add the route. - Missing Content-Type. When you use curl, send
Content-Type: application/json, or the body is not parsed as JSON. - Model name typos. The model ID is
uncensored, in lowercase. A call toGET /v1/modelslists the exact string if you want to confirm. - Oversized body. The request body limit is 8 MB. Pasting an entire book into one message can hit it long before the token limit does.
- Retries without a pause. If you loop on 429 responses with no delay, you make the problem worse. Sleep for the
Retry-Aftervalue when it is present, or a few seconds when it is not.
Failed requests are not charged, so debugging costs nothing in credit. If an error does not match anything above, save the X-Request-Id header from the response and send it through the support page.
