Create chat completion
curl --request POST \
--url https://cloud-api.near.ai/v1/chat/completions \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '
{
"messages": [
{
"role": "<string>",
"content": "<string>",
"name": "<string>",
"tool_call_id": "<string>",
"tool_calls": [
{
"function": {
"arguments": "<string>",
"name": "<string>"
},
"id": "<string>",
"type": "<string>",
"thought_signature": "<string>"
}
]
}
],
"model": "<string>",
"frequency_penalty": 123,
"max_tokens": 123,
"n": 123,
"presence_penalty": 123,
"stop": "<string>",
"stream": true,
"temperature": 123,
"top_p": 123
}
'import requests
url = "https://cloud-api.near.ai/v1/chat/completions"
payload = {
"messages": [
{
"role": "<string>",
"content": "<string>",
"name": "<string>",
"tool_call_id": "<string>",
"tool_calls": [
{
"function": {
"arguments": "<string>",
"name": "<string>"
},
"id": "<string>",
"type": "<string>",
"thought_signature": "<string>"
}
]
}
],
"model": "<string>",
"frequency_penalty": 123,
"max_tokens": 123,
"n": 123,
"presence_penalty": 123,
"stop": "<string>",
"stream": True,
"temperature": 123,
"top_p": 123
}
headers = {
"Authorization": "Bearer <token>",
"Content-Type": "application/json"
}
response = requests.post(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'POST',
headers: {Authorization: 'Bearer <token>', 'Content-Type': 'application/json'},
body: JSON.stringify({
messages: [
{
role: '<string>',
content: '<string>',
name: '<string>',
tool_call_id: '<string>',
tool_calls: [
{
function: {arguments: '<string>', name: '<string>'},
id: '<string>',
type: '<string>',
thought_signature: '<string>'
}
]
}
],
model: '<string>',
frequency_penalty: 123,
max_tokens: 123,
n: 123,
presence_penalty: 123,
stop: '<string>',
stream: true,
temperature: 123,
top_p: 123
})
};
fetch('https://cloud-api.near.ai/v1/chat/completions', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://cloud-api.near.ai/v1/chat/completions",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => json_encode([
'messages' => [
[
'role' => '<string>',
'content' => '<string>',
'name' => '<string>',
'tool_call_id' => '<string>',
'tool_calls' => [
[
'function' => [
'arguments' => '<string>',
'name' => '<string>'
],
'id' => '<string>',
'type' => '<string>',
'thought_signature' => '<string>'
]
]
]
],
'model' => '<string>',
'frequency_penalty' => 123,
'max_tokens' => 123,
'n' => 123,
'presence_penalty' => 123,
'stop' => '<string>',
'stream' => true,
'temperature' => 123,
'top_p' => 123
]),
CURLOPT_HTTPHEADER => [
"Authorization: Bearer <token>",
"Content-Type: application/json"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"strings"
"net/http"
"io"
)
func main() {
url := "https://cloud-api.near.ai/v1/chat/completions"
payload := strings.NewReader("{\n \"messages\": [\n {\n \"role\": \"<string>\",\n \"content\": \"<string>\",\n \"name\": \"<string>\",\n \"tool_call_id\": \"<string>\",\n \"tool_calls\": [\n {\n \"function\": {\n \"arguments\": \"<string>\",\n \"name\": \"<string>\"\n },\n \"id\": \"<string>\",\n \"type\": \"<string>\",\n \"thought_signature\": \"<string>\"\n }\n ]\n }\n ],\n \"model\": \"<string>\",\n \"frequency_penalty\": 123,\n \"max_tokens\": 123,\n \"n\": 123,\n \"presence_penalty\": 123,\n \"stop\": \"<string>\",\n \"stream\": true,\n \"temperature\": 123,\n \"top_p\": 123\n}")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("Authorization", "Bearer <token>")
req.Header.Add("Content-Type", "application/json")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}HttpResponse<String> response = Unirest.post("https://cloud-api.near.ai/v1/chat/completions")
.header("Authorization", "Bearer <token>")
.header("Content-Type", "application/json")
.body("{\n \"messages\": [\n {\n \"role\": \"<string>\",\n \"content\": \"<string>\",\n \"name\": \"<string>\",\n \"tool_call_id\": \"<string>\",\n \"tool_calls\": [\n {\n \"function\": {\n \"arguments\": \"<string>\",\n \"name\": \"<string>\"\n },\n \"id\": \"<string>\",\n \"type\": \"<string>\",\n \"thought_signature\": \"<string>\"\n }\n ]\n }\n ],\n \"model\": \"<string>\",\n \"frequency_penalty\": 123,\n \"max_tokens\": 123,\n \"n\": 123,\n \"presence_penalty\": 123,\n \"stop\": \"<string>\",\n \"stream\": true,\n \"temperature\": 123,\n \"top_p\": 123\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://cloud-api.near.ai/v1/chat/completions")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["Authorization"] = 'Bearer <token>'
request["Content-Type"] = 'application/json'
request.body = "{\n \"messages\": [\n {\n \"role\": \"<string>\",\n \"content\": \"<string>\",\n \"name\": \"<string>\",\n \"tool_call_id\": \"<string>\",\n \"tool_calls\": [\n {\n \"function\": {\n \"arguments\": \"<string>\",\n \"name\": \"<string>\"\n },\n \"id\": \"<string>\",\n \"type\": \"<string>\",\n \"thought_signature\": \"<string>\"\n }\n ]\n }\n ],\n \"model\": \"<string>\",\n \"frequency_penalty\": 123,\n \"max_tokens\": 123,\n \"n\": 123,\n \"presence_penalty\": 123,\n \"stop\": \"<string>\",\n \"stream\": true,\n \"temperature\": 123,\n \"top_p\": 123\n}"
response = http.request(request)
puts response.read_body{
"choices": [
{
"index": 123,
"message": {
"role": "<string>",
"content": "<string>",
"name": "<string>",
"tool_call_id": "<string>",
"tool_calls": [
{
"function": {
"arguments": "<string>",
"name": "<string>"
},
"id": "<string>",
"type": "<string>",
"thought_signature": "<string>"
}
]
},
"finish_reason": "<string>"
}
],
"created": 123,
"id": "<string>",
"model": "<string>",
"object": "<string>",
"usage": {
"completion_tokens": 123,
"prompt_tokens": 123,
"total_tokens": 123,
"completion_tokens_details": {
"reasoning_tokens": 123
},
"prompt_tokens_details": {
"cached_tokens": 123
}
}
}{
"error": {
"message": "<string>",
"type": "<string>",
"code": "<string>",
"param": "<string>"
}
}{
"error": {
"message": "<string>",
"type": "<string>",
"code": "<string>",
"param": "<string>"
}
}{
"error": {
"message": "<string>",
"type": "<string>",
"code": "<string>",
"param": "<string>"
}
}{
"error": {
"message": "<string>",
"type": "<string>",
"code": "<string>",
"param": "<string>"
}
}{
"error": {
"message": "<string>",
"type": "<string>",
"code": "<string>",
"param": "<string>"
}
}Chat
Create chat completion
Generate AI model responses for chat conversations. Supports both streaming and non-streaming modes. OpenAI-compatible endpoint.
POST
/
v1
/
chat
/
completions
Create chat completion
curl --request POST \
--url https://cloud-api.near.ai/v1/chat/completions \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '
{
"messages": [
{
"role": "<string>",
"content": "<string>",
"name": "<string>",
"tool_call_id": "<string>",
"tool_calls": [
{
"function": {
"arguments": "<string>",
"name": "<string>"
},
"id": "<string>",
"type": "<string>",
"thought_signature": "<string>"
}
]
}
],
"model": "<string>",
"frequency_penalty": 123,
"max_tokens": 123,
"n": 123,
"presence_penalty": 123,
"stop": "<string>",
"stream": true,
"temperature": 123,
"top_p": 123
}
'import requests
url = "https://cloud-api.near.ai/v1/chat/completions"
payload = {
"messages": [
{
"role": "<string>",
"content": "<string>",
"name": "<string>",
"tool_call_id": "<string>",
"tool_calls": [
{
"function": {
"arguments": "<string>",
"name": "<string>"
},
"id": "<string>",
"type": "<string>",
"thought_signature": "<string>"
}
]
}
],
"model": "<string>",
"frequency_penalty": 123,
"max_tokens": 123,
"n": 123,
"presence_penalty": 123,
"stop": "<string>",
"stream": True,
"temperature": 123,
"top_p": 123
}
headers = {
"Authorization": "Bearer <token>",
"Content-Type": "application/json"
}
response = requests.post(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'POST',
headers: {Authorization: 'Bearer <token>', 'Content-Type': 'application/json'},
body: JSON.stringify({
messages: [
{
role: '<string>',
content: '<string>',
name: '<string>',
tool_call_id: '<string>',
tool_calls: [
{
function: {arguments: '<string>', name: '<string>'},
id: '<string>',
type: '<string>',
thought_signature: '<string>'
}
]
}
],
model: '<string>',
frequency_penalty: 123,
max_tokens: 123,
n: 123,
presence_penalty: 123,
stop: '<string>',
stream: true,
temperature: 123,
top_p: 123
})
};
fetch('https://cloud-api.near.ai/v1/chat/completions', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://cloud-api.near.ai/v1/chat/completions",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => json_encode([
'messages' => [
[
'role' => '<string>',
'content' => '<string>',
'name' => '<string>',
'tool_call_id' => '<string>',
'tool_calls' => [
[
'function' => [
'arguments' => '<string>',
'name' => '<string>'
],
'id' => '<string>',
'type' => '<string>',
'thought_signature' => '<string>'
]
]
]
],
'model' => '<string>',
'frequency_penalty' => 123,
'max_tokens' => 123,
'n' => 123,
'presence_penalty' => 123,
'stop' => '<string>',
'stream' => true,
'temperature' => 123,
'top_p' => 123
]),
CURLOPT_HTTPHEADER => [
"Authorization: Bearer <token>",
"Content-Type: application/json"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"strings"
"net/http"
"io"
)
func main() {
url := "https://cloud-api.near.ai/v1/chat/completions"
payload := strings.NewReader("{\n \"messages\": [\n {\n \"role\": \"<string>\",\n \"content\": \"<string>\",\n \"name\": \"<string>\",\n \"tool_call_id\": \"<string>\",\n \"tool_calls\": [\n {\n \"function\": {\n \"arguments\": \"<string>\",\n \"name\": \"<string>\"\n },\n \"id\": \"<string>\",\n \"type\": \"<string>\",\n \"thought_signature\": \"<string>\"\n }\n ]\n }\n ],\n \"model\": \"<string>\",\n \"frequency_penalty\": 123,\n \"max_tokens\": 123,\n \"n\": 123,\n \"presence_penalty\": 123,\n \"stop\": \"<string>\",\n \"stream\": true,\n \"temperature\": 123,\n \"top_p\": 123\n}")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("Authorization", "Bearer <token>")
req.Header.Add("Content-Type", "application/json")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}HttpResponse<String> response = Unirest.post("https://cloud-api.near.ai/v1/chat/completions")
.header("Authorization", "Bearer <token>")
.header("Content-Type", "application/json")
.body("{\n \"messages\": [\n {\n \"role\": \"<string>\",\n \"content\": \"<string>\",\n \"name\": \"<string>\",\n \"tool_call_id\": \"<string>\",\n \"tool_calls\": [\n {\n \"function\": {\n \"arguments\": \"<string>\",\n \"name\": \"<string>\"\n },\n \"id\": \"<string>\",\n \"type\": \"<string>\",\n \"thought_signature\": \"<string>\"\n }\n ]\n }\n ],\n \"model\": \"<string>\",\n \"frequency_penalty\": 123,\n \"max_tokens\": 123,\n \"n\": 123,\n \"presence_penalty\": 123,\n \"stop\": \"<string>\",\n \"stream\": true,\n \"temperature\": 123,\n \"top_p\": 123\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://cloud-api.near.ai/v1/chat/completions")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["Authorization"] = 'Bearer <token>'
request["Content-Type"] = 'application/json'
request.body = "{\n \"messages\": [\n {\n \"role\": \"<string>\",\n \"content\": \"<string>\",\n \"name\": \"<string>\",\n \"tool_call_id\": \"<string>\",\n \"tool_calls\": [\n {\n \"function\": {\n \"arguments\": \"<string>\",\n \"name\": \"<string>\"\n },\n \"id\": \"<string>\",\n \"type\": \"<string>\",\n \"thought_signature\": \"<string>\"\n }\n ]\n }\n ],\n \"model\": \"<string>\",\n \"frequency_penalty\": 123,\n \"max_tokens\": 123,\n \"n\": 123,\n \"presence_penalty\": 123,\n \"stop\": \"<string>\",\n \"stream\": true,\n \"temperature\": 123,\n \"top_p\": 123\n}"
response = http.request(request)
puts response.read_body{
"choices": [
{
"index": 123,
"message": {
"role": "<string>",
"content": "<string>",
"name": "<string>",
"tool_call_id": "<string>",
"tool_calls": [
{
"function": {
"arguments": "<string>",
"name": "<string>"
},
"id": "<string>",
"type": "<string>",
"thought_signature": "<string>"
}
]
},
"finish_reason": "<string>"
}
],
"created": 123,
"id": "<string>",
"model": "<string>",
"object": "<string>",
"usage": {
"completion_tokens": 123,
"prompt_tokens": 123,
"total_tokens": 123,
"completion_tokens_details": {
"reasoning_tokens": 123
},
"prompt_tokens_details": {
"cached_tokens": 123
}
}
}{
"error": {
"message": "<string>",
"type": "<string>",
"code": "<string>",
"param": "<string>"
}
}{
"error": {
"message": "<string>",
"type": "<string>",
"code": "<string>",
"param": "<string>"
}
}{
"error": {
"message": "<string>",
"type": "<string>",
"code": "<string>",
"param": "<string>"
}
}{
"error": {
"message": "<string>",
"type": "<string>",
"code": "<string>",
"param": "<string>"
}
}{
"error": {
"message": "<string>",
"type": "<string>",
"code": "<string>",
"param": "<string>"
}
}Authorizations
API key for programmatic access (Authorization: Bearer sk-<api_key>)
Body
application/json
Show child attributes
Show child attributes
OpenAI stop accepts either a single string or an array of strings.
Response
Completion generated successfully
Show child attributes
Show child attributes
Usage for chat/completions endpoints. Serializes as prompt_tokens, completion_tokens, prompt_tokens_details, completion_tokens_details, total_tokens.
Show child attributes
Show child attributes
Unknown top-level fields from the provider (e.g. system_fingerprint, prompt_logprobs). Re-emitted when serializing so we do not drop them.