Text Generation and Chat
Generate text with Nex N2.6. All three protocol examples use the same model and prompt. If you already use an SDK, choose its protocol. For a new integration, start with Chat Completions.
Prepare your API key and choose a model
Nex N2.6 is free for a limited time, and calls consume 0 credits. All valid MOSS API Keys can call it. Production HTTP requests use https://api.mosi.cn. Before running the examples below, set MOSS_API_ORIGIN to https://api.mosi.cn and MOSS_API_KEY to your MOSS API Key. Set the OpenAI SDK base_url to https://api.mosi.cn/v1.
Use nex-n2.6 for routine calls or nex-n2.6-2026-11-05 to pin a version. You can omit version. If you specify it, use 2026-11-05 and make sure it matches the snapshot selected by model.
Choose a protocol
| Existing client | Endpoint | Authentication |
|---|---|---|
| OpenAI Chat Completions or a new integration | POST /v1/chat/completions | Authorization: Bearer <API Key> |
| OpenAI Responses | POST /v1/responses | Authorization: Bearer <API Key> |
| Anthropic Messages | POST /v1/messages | x-api-key and anthropic-version: 2023-06-01 |
Send your first request
Choose a protocol and send a request. The three examples use the same prompt. Follow the response format for the protocol you choose.
Chat Completions
Run the example in any of the three languages. The Python examples use requests. The TypeScript examples require a Node.js environment with fetch.
curl -X POST "$MOSS_API_ORIGIN/v1/chat/completions" \
-H 'Content-Type: application/json' \
-H "Authorization: Bearer $MOSS_API_KEY" \
-d '{
"model": "nex-n2.6",
"messages": [
{
"role": "user",
"content": "Reply with only the result of 17 × 23."
}
],
"max_tokens": 1024
}'Read the reply from choices[0].message.content.
Responses
curl -X POST "$MOSS_API_ORIGIN/v1/responses" \
-H 'Content-Type: application/json' \
-H "Authorization: Bearer $MOSS_API_KEY" \
-d '{
"model": "nex-n2.6",
"input": "Reply with only the result of 17 × 23.",
"max_output_tokens": 1024,
"store": false
}'Find an item in output with type set to message, then read text from its output_text content block. Check status. completed indicates completion. On incomplete, read any generated content and available usage.
Messages
curl -X POST "$MOSS_API_ORIGIN/v1/messages" \
-H 'Content-Type: application/json' \
-H "x-api-key: $MOSS_API_KEY" \
-H 'anthropic-version: 2023-06-01' \
-d '{
"model": "nex-n2.6",
"messages": [
{
"role": "user",
"content": "Reply with only the result of 17 × 23."
}
],
"max_tokens": 1024
}'Iterate over content and read the blocks whose type is text. You can estimate input usage with Count Tokens. Use usage from the generation response for actual usage.
Stream output and continue a conversation
Add stream: true to the request body and use curl -N to see deltas as they arrive. In Chat Completions, read a text delta only when the choice and its content are present. Process usage separately because the usage chunk has an empty choices array. Check the HTTP status first. Once streaming starts, check for error events and the expected termination marker. Treat an early disconnect as an incomplete response.
| Protocol | Text deltas | Termination and usage |
|---|---|---|
| Chat Completions | choices[].delta.content | Stop reading when you receive [DONE]. Set stream_options.include_usage to receive usage at the end of the stream. |
| Responses | delta in response.output_text.delta | response.completed marks successful completion. Read usage from response.usage. On response.incomplete, keep the output and usage already returned. |
| Messages | text_delta in content_block_delta | Stop reading when you receive message_stop. See message_start and message_delta for usage. |
To continue a conversation, send the relevant history in messages for Chat Completions and Messages. For stateless Responses calls, send the history in input.
Media, tools, and model versions
All three generation protocols support text and images. Chat Completions and Responses accept MP4 and WebM through video_url. Messages does not support video. Files, file_id, and asset library references are currently unsupported. Public media URLs must be accessible to MOSS. The entire request body, including encoded media, must be at most 10 MiB. With Chat Completions and Messages, the client executes functions and sends the results back.