Chat Completions
The Chat Completions endpoint is the primary way to interact with language models. It is fully compatible with OpenAI’s Chat Completions API.
POST https://api.tokensupernova.com/v1/chat/completionsRequest Body
Section titled “Request Body”| Parameter | Type | Required | Description |
|---|---|---|---|
model | string | ✅ | Model ID. See Models → |
messages | array | ✅ | List of messages in the conversation |
temperature | number | Sampling temperature (0-2). Default: 1.0 | |
top_p | number | Nucleus sampling (0-1). Default: 1.0 | |
max_tokens | integer | Maximum tokens to generate | |
stream | boolean | Stream responses. See Streaming → | |
stop | string/array | Stop sequences | |
frequency_penalty | number | -2.0 to 2.0. Default: 0 | |
presence_penalty | number | -2.0 to 2.0. Default: 0 |
Message Format
Section titled “Message Format”{ "role": "user", "content": "Your message here"}| Role | Description |
|---|---|
system | Sets the behavior of the assistant (optional, first message only) |
user | Messages from the end user |
assistant | Previous responses from the model (for multi-turn) |
Example Request
Section titled “Example Request”from openai import OpenAI
client = OpenAI( api_key="tsn_live_xxx", base_url="https://api.tokensupernova.com/v1",)
response = client.chat.completions.create( model="deepseek-chat", temperature=0.7, max_tokens=1024, messages=[ {"role": "system", "content": "You are a helpful assistant."}, {"role": "user", "content": "What is the capital of Japan?"}, ],)
print(response.choices[0].message.content)# Output: The capital of Japan is Tokyo.Example Response
Section titled “Example Response”{ "id": "chatcmpl-abc123", "object": "chat.completion", "created": 1700000000, "model": "deepseek-chat", "choices": [ { "index": 0, "message": { "role": "assistant", "content": "The capital of Japan is Tokyo." }, "finish_reason": "stop" } ], "usage": { "prompt_tokens": 25, "completion_tokens": 9, "total_tokens": 34 }}Multi-turn Conversation
Section titled “Multi-turn Conversation”response = client.chat.completions.create( model="deepseek-chat", messages=[ {"role": "user", "content": "What is 2+2?"}, {"role": "assistant", "content": "2+2 equals 4."}, {"role": "user", "content": "Multiply that by 3."}, ],)