EN ▾
Get API key

CosyVoice API Explained: Speech Plus a Text LLM

A search for a CosyVoice API usually means one of two things: a speech synthesis endpoint, or the text model that writes what gets spoken. This page explains the split and covers the text half.

Updated

A text generator connected by a pipe to a speaker, showing the two halves of a voice pipeline

Key points

What a CosyVoice API usually refers to

When someone types cosyvoice api into a search box, they are normally looking for a way to call a speech synthesis model from code. CosyVoice is a text-to-speech project: you give it a string of text (and often a short reference voice or a speaker choice), and it returns audio. It is published as an open-source model family, and some cloud services also offer hosted speech endpoints built on models of this type. Check the project page or your provider's documentation for what is currently available and how it is priced.

That is only half of a voice product, though. Something has to decide what the voice says. In a voice assistant, a game character, an audio drama tool or a narration pipeline, the words come from a language model, and the speech model turns those words into sound. The two parts are separate programs with separate APIs, separate bills and separate failure modes.

This site covers the text half. It is a hosted API for one open-weight text model, reachable through the same request format that OpenAI SDKs use. It does not make audio, it is not the official API of CosyVoice or of any company behind a speech model, and it does not route to other vendors. If you need sound, you pair it with a speech engine of your choice.

The two halves of a voice pipeline

It helps to draw the pipeline once, because most confusion comes from mixing the stages up.

  1. Input. Text typed by a user, or speech converted to text by a recognition model.
  2. Text generation. A language model reads the input plus a system prompt and writes the reply or the script.
  3. Speech synthesis. A text-to-speech model (CosyVoice is one example) converts that reply into audio.
  4. Playback or export. Audio goes to a speaker, a game engine, or a file.

Step 2 is where this API sits. It takes messages in and returns text out, either as one response or as a stream of small pieces. Step 3 is where a speech model sits. The only thing that passes between them is plain text, which is good news: you can swap either part without touching the other.

One practical consequence is that the text model never needs to know which voice will read its output. You do, however, want to shape the text for speaking. Written prose and spoken prose are different. Spoken lines are shorter, avoid parentheses and tables, spell out symbols, and skip markdown. That shaping happens in your system prompt, which is the part you control fully.

What this API gives you, and what it does not

Here is the product in plain terms, so you can decide whether it fits your pipeline.

  • OpenAI-compatible: point any OpenAI SDK or client at https://api.cosyvoice.top/v1, use your key as a Bearer token, and set the model to uncensored.
  • Two endpoints: POST /v1/chat/completions and GET /v1/models.
  • Streaming over SSE, tool calling, JSON mode, and the usual sampling settings (temperature, top_p, stop, seed, penalties).
  • A 100,000-token context window, shared between prompt and completion.
  • One open-weight model, run by an independent provider, tuned to answer without content refusals for lawful adult use. No sexual content involving minors, ever.

And the limits that matter for a speech project: it is text only. There is no audio output, no voice cloning, no image or video generation, no embeddings and no fine-tuning. If your plan involves any of those, they live in other tools.

The no-refusal tuning is relevant to voice work more than people expect. Fiction, character dialogue and roleplay for adult audiences often include violence, grief, crime or crude language, and a model that stops mid-scene breaks the audio flow. Here the model is tuned to keep going within the law. The docs list the exact request fields for controlling output length and stopping points.

Wiring the text half into a speech engine

The first request is the same as for any OpenAI-compatible service. Create a key on the API key page, then run this:

curl https://api.cosyvoice.top/v1/chat/completions \
  -H "Authorization: Bearer $API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "uncensored",
    "messages": [
      {"role": "system", "content": "You write short spoken replies. Plain sentences only, no markdown, no lists."},
      {"role": "user", "content": "Greet a customer who just called a lighthouse tour booking line."}
    ]
  }'

The reply arrives under choices[0].message.content. Pass that string to your speech engine and you have the simplest possible pipeline. The same request in Python with the openai package:

from openai import OpenAI

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

def write_reply(user_text: str) -> str:
    resp = client.chat.completions.create(
        model="uncensored",
        messages=[
            {"role": "system", "content": "Reply in two or three short spoken sentences. No markdown."},
            {"role": "user", "content": user_text},
        ],
        temperature=0.7,
        max_tokens=200,
    )
    return resp.choices[0].message.content

text = write_reply("Tell me what the tour includes.")
print(text)  # hand this string to your text-to-speech call

Notice that max_tokens is set here only to keep spoken replies short. It is optional on this API; without it the completion may use whatever is left of the 100,000-token window.

Streaming text into speech sentence by sentence

Waiting for a whole reply before you start speaking makes a voice product feel slow. The standard fix is to stream the text and send each finished sentence to the speech engine as soon as it appears. With stream: true the API sends server-sent events, and the OpenAI SDK exposes them as an iterator.

import re
from openai import OpenAI

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

def sentences(messages):
    buf = ""
    stream = client.chat.completions.create(
        model="uncensored",
        messages=messages,
        stream=True,
    )
    for chunk in stream:
        if not chunk.choices:
            continue
        buf += chunk.choices[0].delta.content or ""
        while True:
            m = re.search(r"[.?]\s", buf)
            if not m:
                break
            yield buf[: m.end()].strip()
            buf = buf[m.end():]
    if buf.strip():
        yield buf.strip()

for line in sentences([{"role": "user", "content": "Describe the harbor at dawn."}]):
    print("SPEAK:", line)  # replace print with your speech call

Two details are easy to get wrong. First, abbreviations and decimals can fool a naive sentence splitter, so either tell the model in the system prompt to avoid them or use a splitter that knows about them. Second, a streamed request holds its concurrency slot until the stream ends. A full key allows 8 concurrent requests, so if each of your voice sessions keeps a stream open for the length of a long reply, eight simultaneous sessions is your ceiling. Trial keys allow 2.

What the text half costs

Pricing is per token and prepaid: $0.15 per 1M input tokens and $0.50 per 1M output tokens. There is no subscription, failed or refused requests are not charged, and credit does not expire. Top-ups start at $20 and go up to $500 in whole dollars, with a bonus of 5% from $50, 10% from $100 and 15% from $200. You can pay with crypto (USDT on TRC20, USDC on Base). Details are on the pricing page.

A worked example for a voice assistant turn: a prompt of 1,500 tokens (system prompt plus recent history) and a reply of 600 tokens. Input costs 1,500 x $0.15 / 1,000,000 = $0.000225. Output costs 600 x $0.50 / 1,000,000 = $0.0003. One turn is $0.000525, so 1,000 turns cost $0.525. Speech synthesis is billed separately by whoever provides it, and for voice products it is often the larger line.

New accounts can claim $0.50 of trial credit with one click on the API key page after sign-up. It needs no card, lasts 7 days, and is limited to one per person. At the turn size above it covers several hundred test turns, which is plenty to wire up a prototype.

Common mistakes in a speech plus LLM setup

Sending markdown to a speech engine

Asterisks, bullet markers and headings get read aloud or cause odd pauses. Tell the model in the system prompt to write plain sentences, and strip leftovers in code before synthesis.

Letting replies grow too long

A speaker cannot skim. Three to five sentences per turn is a good starting range for conversation, and you can set a stop sequence or a modest max_tokens as a safety net.

Ignoring 429 responses

If you exceed 300 requests per minute you get HTTP 429 with code rate_limited. If you have too many requests in flight you get code concurrency. Temporary overload also returns 429, with a Retry-After: 5 header. Wait the stated time and retry, ideally with a small queue in front of the API.

Expecting a vendor API

This is a separate hosted service for one open-weight model. If you need the official endpoint of a particular speech or language model vendor, go to that vendor. If you need a text model that is tuned to answer without content refusals for lawful adult use and speaks the OpenAI protocol, the quickstart shows the rest of the setup. Related reading: the Seedream API guide.

Questions and answers

Does this site offer text-to-speech?

No. It is a text-only API. You use it to generate the words and send them to a separate speech engine.

Is this the official CosyVoice API?

No. It is an independent hosted service for one open-weight text model and has no affiliation with any speech or language model vendor.

Can I use the OpenAI SDK?

Yes. Set the base URL to https://api.cosyvoice.top/v1, pass your key, and use the model ID uncensored.

How much context can I send?

The window is 100,000 tokens, counting the prompt and the completion together, which is enough for long scripts and a lot of conversation history.

Is there a free tier?

There is a one-time $0.50 trial credit, claimed with one click after sign-up, valid for 7 days and needing no card. After that you pay per token from prepaid credit.

Your key is one form away

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

Get API key