Skip to content

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/completions
ParameterTypeRequiredDescription
modelstringModel ID. See Models →
messagesarrayList of messages in the conversation
temperaturenumberSampling temperature (0-2). Default: 1.0
top_pnumberNucleus sampling (0-1). Default: 1.0
max_tokensintegerMaximum tokens to generate
streambooleanStream responses. See Streaming →
stopstring/arrayStop sequences
frequency_penaltynumber-2.0 to 2.0. Default: 0
presence_penaltynumber-2.0 to 2.0. Default: 0
{
"role": "user",
"content": "Your message here"
}
RoleDescription
systemSets the behavior of the assistant (optional, first message only)
userMessages from the end user
assistantPrevious responses from the model (for multi-turn)
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.
{
"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
}
}
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."},
],
)