Chat Completions API
Create Chat Completions
Endpoint to generate conversational responses based on user-provided input messages.
POST https://api.relax.ai/v1/chat/completions
Example Request
curl https://api.relax.ai/v1/chat/completions \ -H "Content-Type: application/json" \ -H "Authorization: Bearer $RELAX_API_KEY" \ -d '{ "model": "Llama-4-Maverick-17B-128E", "messages": [{"role": "user", "content": "What is the capital of the UK?"}], "temperature": 0.7 }'
import openai
client = OpenAI( api_key = RELAX_API_KEY, base_url = 'https://api.relax.ai/v1/',)
response = client.chat.completions.create( model = "DeepSeek-R1-0528", messages = [ {"role": "system", "content": "You are a helpful assistant."}, {"role": "user", "content": "Tell me about climate change."} ], temperature = 0.7, max_tokens = 100)
print(response.choices[0].message.content)
import { OpenAI } from "openai";
const openai = new OpenAI({ apiKey: RELAX_API_KEY, baseUrl: 'https://api.relax.ai/v1/'});
async function main() { const completion = await openai.chat.completions.create({ messages: [{ role: "user", content: "What is the capital of the UK?" }], model: "Llama-4-Maverick-17B-128E", temperature: 0.7 });
console.log(completion.choices[0]);}
main();
Response
Returns a Chat Completions object.
Chat Completions Response
{ "id": "chatcmpl-1c05717f8d68454f9375d6706cc275e6", "object": "chat.completion", "created": 1744034860, "model": "Llama-4-Maverick-17B-128E", "choices": [ { "index": 0, "message": { "role": "assistant", "content": "The capital of the United Kingdom is London." }, "finish_reason": "stop", "content_filter_results": { "hate": { "filtered": false }, "self_harm": { "filtered": false }, "sexual": { "filtered": false }, "violence": { "filtered": false }, "jailbreak": { "filtered": false, "detected": false }, "profanity": { "filtered": false, "detected": false } } } ], "usage": { "prompt_tokens": 76, "completion_tokens": 10, "total_tokens": 86, "prompt_tokens_details": null, "completion_tokens_details": null }, "system_fingerprint": ""}
Request Body
The following parameters can be included in the request body:
Chat Completions Request Body
model
- Type: string
- Required: Yes
- Description: The model name to use for generating the completion.
messages
- Type: array
- Required: Yes
- Description: A list of message objects representing the conversation history.
temperature
- Type: float
- Required: No
- Description: Controls randomness. Lower values make output more focused and deterministic.
top_p
- Type: float
- Required: No
- Description: An alternative to temperature that controls diversity via nucleus sampling.
max_tokens
- Type: integer
- Required: No
- Description: The maximum number of tokens to generate for the completion.
stop
- Type: string
- Required: No
- Description: A sequence where the API will stop generating further tokens.
presence_penalty
- Type: float
- Required: No
- Description: Penalizes new tokens based on whether they appear in the text so far.
frequency_penalty
- Type: float
- Required: No
- Description: Penalizes new tokens based on their cumulative frequency in the generated text.
logprobs
- Type: boolean
- Required: No
- Description: If set to true, returns the log probabilities of each token in the output.
user
- Type: string
- Required: No
- Description: An optional identifier representing the end-user making the request.
Streaming
The relaxAI API supports response streaming, enabling clients to receive partial results for specific requests in real-time.
Streaming is available for the relaxAI Chat Completions endpoint. This section will cover streaming functions in Chat Completions, with examples on how to use.
import openai
client = OpenAI( api_key = RELAX_API_KEY, base_url = 'https://api.relax.ai/v1/',)
stream = client.chat.completions.create( model="Llama-4-Maverick-17B-128E", messages=[ {"role": "user", "content": "What is the capital of the UK?"} ], stream=True)
for chunk in stream: if chunk.choices[0].delta.content is not None: print(chunk.choices[0].delta.content, end="")
import { OpenAI } from "openai";
const openai = new OpenAI({ apiKey: RELAX_API_KEY, baseUrl: 'https://api.relax.ai/v1/'});
async function main() { const stream = await openai.chat.completions.create({ model: "Llama-4-Maverick-17B-128E", messages: [{ role: "user", content: "What is the capital of the UK?" }], store: true, stream: true, }); for await (const chunk of stream) { process.stdout.write(chunk.choices[0]?.delta?.content || ""); }}
main();
Tool Calling
relaxAI supports tool calling to enable seamless integration of custom tools into your AI workflows, allowing you to define and pass bespoke functionality to the Chat Completions endpoint. This feature allows developers to extend the capabilities of our AI models with tools tailored to their specific use cases, enhancing the overall flexibility and effectiveness of their applications.
To use custom tools, you will need to define a list of functions the model may generate JSON inputs for. Currently a maximum of 128 functions may be defined.
import openai
client = OpenAI( api_key = RELAX_API_KEY, base_url = 'https://api.relax.ai/v1/',)
tools = [ { "type": "function", "function": { "name": "get_current_weather", "description": "Get the current weather in a given location", "parameters": { "type": "object", "properties": { "location": { "type": "string", "description": "The city and state, e.g. San Francisco, CA", }, "unit": {"type": "string", "enum": ["celsius", "fahrenheit"]}, }, "required": ["location"], }, } }]messages = [{"role": "user", "content": "What's the weather like in London today?"}]completion = client.chat.completions.create( model="DeepSeek-R1-0528", messages=messages, tools=tools, tool_choice="auto")
import OpenAI from "openai";
const openai = new OpenAI({apiKey: RELAX_API_KEY,baseUrl: "https://api.relax.ai/v1/"});
async function main() {const messages = [{"role": "user", "content": "What's the weather like in Boston today?"}];const tools = [ { "type": "function", "function": { "name": "get_current_weather", "description": "Get the current weather in a given location", "parameters": { "type": "object", "properties": { "location": { "type": "string", "description": "The city and state, e.g. San Francisco, CA", }, "unit": {"type": "string", "enum": ["celsius", "fahrenheit"]}, }, "required": ["location"], }, } }];
const response = await openai.chat.completions.create({model: "DeepSeek-R1-0528",messages: messages,tools: tools,tool_choice: "auto",});
console.log(response);}
main();