Configure Base URL and Key
Start by obtaining an API key from the Get API key page. You can sign in with Google or use an email and password. The key is displayed immediately and is the only active key for your account; generating a new one replaces the previous key.
Set your base URL to https://api.cosyvoice.top/v1. Use the model ID uncensored for all requests. This endpoint is compatible with any OpenAI-compatible client, allowing you to swap your base URL without changing your application code.
Basic Text Completion Request
Send a standard POST /v1/chat/completions request to generate text. The API accepts messages arrays and returns raw text output. This is ideal for prompt engineering, script generation, or post-processing in your pipeline.
Ensure your payload includes the model identifier and your authentication header. The API does not perform image, audio, or video generation itself; it provides the text layer that powers those workflows.
curl
Python SDK Integration
Use the official OpenAI Python SDK to interact with the API. Initialize the client with your API key and the CosyVoice base URL. This approach allows you to leverage existing Python codebases with minimal changes.
Pass your messages and set the model to uncensored. The SDK handles the HTTP requests and parses the JSON responses automatically. This method is recommended for server-side integration in audio or video generation pipelines.
python
Node SDK Usage
For JavaScript or TypeScript environments, use the OpenAI Node SDK. Configure the base URL and API key during initialization. This enables seamless integration into web applications or Node.js services that require text completion.
Call the chat.completions.create() method with the uncensored model. The SDK manages the connection and response parsing, allowing you to focus on integrating the text output into your larger creative pipeline.
node
Streaming Responses with SSE
Enable streaming by setting stream: true in your request. The API returns Server-Sent Events (SSE), delivering tokens in real-time. This is useful for progressive text display or real-time processing in audio pipelines.
Each chunk contains partial text. The final chunk includes token usage statistics. Streaming reduces perceived latency and allows your application to begin processing text before the full response is generated.
stream
Rate Limits, Errors, and Context
The API enforces a limit of 300 requests per minute per key and allows 8 concurrent requests. The maximum request body size is 8 MB. The context window is 100,000 tokens (prompt + completion), with no separate output cap.
Handle errors appropriately: 401 indicates an invalid key, 402 means insufficient credit, and 429 signals rate limiting. Credit is prepaid and never expires. Errors and refusals do not consume tokens, ensuring you only pay for successful completions.
cURL
curl https://api.cosyvoice.top/v1/chat/completions \
-H "Authorization: Bearer $API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "uncensored",
"messages": [{"role": "user", "content": "Write a blunt product review of a cheap VPN."}]
}'Python
from openai import OpenAI
client = OpenAI(base_url="https://api.cosyvoice.top/v1", api_key="YOUR_KEY")
resp = client.chat.completions.create(
model="uncensored",
messages=[{"role": "user", "content": "Summarise this thread without softening it."}],
)
print(resp.choices[0].message.content)Node.js
import OpenAI from "openai";
const client = new OpenAI({ baseURL: "https://api.cosyvoice.top/v1", apiKey: process.env.API_KEY });
const resp = await client.chat.completions.create({
model: "uncensored",
messages: [{ role: "user", content: "Draft a villain monologue for my game." }],
});
console.log(resp.choices[0].message.content);Streaming
stream = client.chat.completions.create(
model="uncensored",
messages=[{"role": "user", "content": "Tell the story in second person."}],
stream=True,
)
for chunk in stream:
if chunk.choices and chunk.choices[0].delta.content:
print(chunk.choices[0].delta.content, end="", flush=True)