Chat Completions (OpenAI-compatible)
curl --request POST \
--url https://api.swarms.world/v1/chat/completions \
--header 'Content-Type: application/json' \
--header 'x-api-key: <x-api-key>' \
--data '
{
"model": "<string>",
"messages": [
{
"content": "<string>",
"name": "<string>",
"tool_calls": [
{}
],
"tool_call_id": "<string>"
}
],
"temperature": 0.5,
"top_p": 123,
"n": 1,
"stream": false,
"max_tokens": 2,
"max_completion_tokens": 2,
"presence_penalty": 123,
"frequency_penalty": 123,
"stop": "<string>",
"user": "<string>",
"max_loops": 1,
"tools": [
{}
],
"tool_choice": "<string>"
}
'import requests
url = "https://api.swarms.world/v1/chat/completions"
payload = {
"model": "<string>",
"messages": [
{
"content": "<string>",
"name": "<string>",
"tool_calls": [{}],
"tool_call_id": "<string>"
}
],
"temperature": 0.5,
"top_p": 123,
"n": 1,
"stream": False,
"max_tokens": 2,
"max_completion_tokens": 2,
"presence_penalty": 123,
"frequency_penalty": 123,
"stop": "<string>",
"user": "<string>",
"max_loops": 1,
"tools": [{}],
"tool_choice": "<string>"
}
headers = {
"x-api-key": "<x-api-key>",
"Content-Type": "application/json"
}
response = requests.post(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'POST',
headers: {'x-api-key': '<x-api-key>', 'Content-Type': 'application/json'},
body: JSON.stringify({
model: '<string>',
messages: [
{
content: '<string>',
name: '<string>',
tool_calls: [{}],
tool_call_id: '<string>'
}
],
temperature: 0.5,
top_p: 123,
n: 1,
stream: false,
max_tokens: 2,
max_completion_tokens: 2,
presence_penalty: 123,
frequency_penalty: 123,
stop: '<string>',
user: '<string>',
max_loops: 1,
tools: [{}],
tool_choice: '<string>'
})
};
fetch('https://api.swarms.world/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://api.swarms.world/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([
'model' => '<string>',
'messages' => [
[
'content' => '<string>',
'name' => '<string>',
'tool_calls' => [
[
]
],
'tool_call_id' => '<string>'
]
],
'temperature' => 0.5,
'top_p' => 123,
'n' => 1,
'stream' => false,
'max_tokens' => 2,
'max_completion_tokens' => 2,
'presence_penalty' => 123,
'frequency_penalty' => 123,
'stop' => '<string>',
'user' => '<string>',
'max_loops' => 1,
'tools' => [
[
]
],
'tool_choice' => '<string>'
]),
CURLOPT_HTTPHEADER => [
"Content-Type: application/json",
"x-api-key: <x-api-key>"
],
]);
$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://api.swarms.world/v1/chat/completions"
payload := strings.NewReader("{\n \"model\": \"<string>\",\n \"messages\": [\n {\n \"content\": \"<string>\",\n \"name\": \"<string>\",\n \"tool_calls\": [\n {}\n ],\n \"tool_call_id\": \"<string>\"\n }\n ],\n \"temperature\": 0.5,\n \"top_p\": 123,\n \"n\": 1,\n \"stream\": false,\n \"max_tokens\": 2,\n \"max_completion_tokens\": 2,\n \"presence_penalty\": 123,\n \"frequency_penalty\": 123,\n \"stop\": \"<string>\",\n \"user\": \"<string>\",\n \"max_loops\": 1,\n \"tools\": [\n {}\n ],\n \"tool_choice\": \"<string>\"\n}")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("x-api-key", "<x-api-key>")
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://api.swarms.world/v1/chat/completions")
.header("x-api-key", "<x-api-key>")
.header("Content-Type", "application/json")
.body("{\n \"model\": \"<string>\",\n \"messages\": [\n {\n \"content\": \"<string>\",\n \"name\": \"<string>\",\n \"tool_calls\": [\n {}\n ],\n \"tool_call_id\": \"<string>\"\n }\n ],\n \"temperature\": 0.5,\n \"top_p\": 123,\n \"n\": 1,\n \"stream\": false,\n \"max_tokens\": 2,\n \"max_completion_tokens\": 2,\n \"presence_penalty\": 123,\n \"frequency_penalty\": 123,\n \"stop\": \"<string>\",\n \"user\": \"<string>\",\n \"max_loops\": 1,\n \"tools\": [\n {}\n ],\n \"tool_choice\": \"<string>\"\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.swarms.world/v1/chat/completions")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["x-api-key"] = '<x-api-key>'
request["Content-Type"] = 'application/json'
request.body = "{\n \"model\": \"<string>\",\n \"messages\": [\n {\n \"content\": \"<string>\",\n \"name\": \"<string>\",\n \"tool_calls\": [\n {}\n ],\n \"tool_call_id\": \"<string>\"\n }\n ],\n \"temperature\": 0.5,\n \"top_p\": 123,\n \"n\": 1,\n \"stream\": false,\n \"max_tokens\": 2,\n \"max_completion_tokens\": 2,\n \"presence_penalty\": 123,\n \"frequency_penalty\": 123,\n \"stop\": \"<string>\",\n \"user\": \"<string>\",\n \"max_loops\": 1,\n \"tools\": [\n {}\n ],\n \"tool_choice\": \"<string>\"\n}"
response = http.request(request)
puts response.read_body{
"id": "<string>",
"created": 123,
"model": "<string>",
"choices": [
{
"message": {
"role": "system",
"content": "<string>",
"name": "<string>",
"tool_calls": [
{}
],
"tool_call_id": "<string>"
},
"index": 0,
"finish_reason": "stop"
}
],
"usage": {
"prompt_tokens": 0,
"completion_tokens": 0,
"total_tokens": 0
},
"object": "chat.completion"
}{
"detail": [
{
"loc": [
"<string>"
],
"msg": "<string>",
"type": "<string>",
"input": "<unknown>",
"ctx": {}
}
]
}OpenAI Compatible
Chat Completions (OpenAI-compatible)
OpenAI-compatible chat completions endpoint. Accepts the standard OpenAI request schema and returns the standard OpenAI response schema. Supports both streaming (SSE) and non-streaming modes. Works as a drop-in replacement with the OpenAI Python and TypeScript SDKs.
POST
/
v1
/
chat
/
completions
Chat Completions (OpenAI-compatible)
curl --request POST \
--url https://api.swarms.world/v1/chat/completions \
--header 'Content-Type: application/json' \
--header 'x-api-key: <x-api-key>' \
--data '
{
"model": "<string>",
"messages": [
{
"content": "<string>",
"name": "<string>",
"tool_calls": [
{}
],
"tool_call_id": "<string>"
}
],
"temperature": 0.5,
"top_p": 123,
"n": 1,
"stream": false,
"max_tokens": 2,
"max_completion_tokens": 2,
"presence_penalty": 123,
"frequency_penalty": 123,
"stop": "<string>",
"user": "<string>",
"max_loops": 1,
"tools": [
{}
],
"tool_choice": "<string>"
}
'import requests
url = "https://api.swarms.world/v1/chat/completions"
payload = {
"model": "<string>",
"messages": [
{
"content": "<string>",
"name": "<string>",
"tool_calls": [{}],
"tool_call_id": "<string>"
}
],
"temperature": 0.5,
"top_p": 123,
"n": 1,
"stream": False,
"max_tokens": 2,
"max_completion_tokens": 2,
"presence_penalty": 123,
"frequency_penalty": 123,
"stop": "<string>",
"user": "<string>",
"max_loops": 1,
"tools": [{}],
"tool_choice": "<string>"
}
headers = {
"x-api-key": "<x-api-key>",
"Content-Type": "application/json"
}
response = requests.post(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'POST',
headers: {'x-api-key': '<x-api-key>', 'Content-Type': 'application/json'},
body: JSON.stringify({
model: '<string>',
messages: [
{
content: '<string>',
name: '<string>',
tool_calls: [{}],
tool_call_id: '<string>'
}
],
temperature: 0.5,
top_p: 123,
n: 1,
stream: false,
max_tokens: 2,
max_completion_tokens: 2,
presence_penalty: 123,
frequency_penalty: 123,
stop: '<string>',
user: '<string>',
max_loops: 1,
tools: [{}],
tool_choice: '<string>'
})
};
fetch('https://api.swarms.world/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://api.swarms.world/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([
'model' => '<string>',
'messages' => [
[
'content' => '<string>',
'name' => '<string>',
'tool_calls' => [
[
]
],
'tool_call_id' => '<string>'
]
],
'temperature' => 0.5,
'top_p' => 123,
'n' => 1,
'stream' => false,
'max_tokens' => 2,
'max_completion_tokens' => 2,
'presence_penalty' => 123,
'frequency_penalty' => 123,
'stop' => '<string>',
'user' => '<string>',
'max_loops' => 1,
'tools' => [
[
]
],
'tool_choice' => '<string>'
]),
CURLOPT_HTTPHEADER => [
"Content-Type: application/json",
"x-api-key: <x-api-key>"
],
]);
$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://api.swarms.world/v1/chat/completions"
payload := strings.NewReader("{\n \"model\": \"<string>\",\n \"messages\": [\n {\n \"content\": \"<string>\",\n \"name\": \"<string>\",\n \"tool_calls\": [\n {}\n ],\n \"tool_call_id\": \"<string>\"\n }\n ],\n \"temperature\": 0.5,\n \"top_p\": 123,\n \"n\": 1,\n \"stream\": false,\n \"max_tokens\": 2,\n \"max_completion_tokens\": 2,\n \"presence_penalty\": 123,\n \"frequency_penalty\": 123,\n \"stop\": \"<string>\",\n \"user\": \"<string>\",\n \"max_loops\": 1,\n \"tools\": [\n {}\n ],\n \"tool_choice\": \"<string>\"\n}")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("x-api-key", "<x-api-key>")
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://api.swarms.world/v1/chat/completions")
.header("x-api-key", "<x-api-key>")
.header("Content-Type", "application/json")
.body("{\n \"model\": \"<string>\",\n \"messages\": [\n {\n \"content\": \"<string>\",\n \"name\": \"<string>\",\n \"tool_calls\": [\n {}\n ],\n \"tool_call_id\": \"<string>\"\n }\n ],\n \"temperature\": 0.5,\n \"top_p\": 123,\n \"n\": 1,\n \"stream\": false,\n \"max_tokens\": 2,\n \"max_completion_tokens\": 2,\n \"presence_penalty\": 123,\n \"frequency_penalty\": 123,\n \"stop\": \"<string>\",\n \"user\": \"<string>\",\n \"max_loops\": 1,\n \"tools\": [\n {}\n ],\n \"tool_choice\": \"<string>\"\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.swarms.world/v1/chat/completions")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["x-api-key"] = '<x-api-key>'
request["Content-Type"] = 'application/json'
request.body = "{\n \"model\": \"<string>\",\n \"messages\": [\n {\n \"content\": \"<string>\",\n \"name\": \"<string>\",\n \"tool_calls\": [\n {}\n ],\n \"tool_call_id\": \"<string>\"\n }\n ],\n \"temperature\": 0.5,\n \"top_p\": 123,\n \"n\": 1,\n \"stream\": false,\n \"max_tokens\": 2,\n \"max_completion_tokens\": 2,\n \"presence_penalty\": 123,\n \"frequency_penalty\": 123,\n \"stop\": \"<string>\",\n \"user\": \"<string>\",\n \"max_loops\": 1,\n \"tools\": [\n {}\n ],\n \"tool_choice\": \"<string>\"\n}"
response = http.request(request)
puts response.read_body{
"id": "<string>",
"created": 123,
"model": "<string>",
"choices": [
{
"message": {
"role": "system",
"content": "<string>",
"name": "<string>",
"tool_calls": [
{}
],
"tool_call_id": "<string>"
},
"index": 0,
"finish_reason": "stop"
}
],
"usage": {
"prompt_tokens": 0,
"completion_tokens": 0,
"total_tokens": 0
},
"object": "chat.completion"
}{
"detail": [
{
"loc": [
"<string>"
],
"msg": "<string>",
"type": "<string>",
"input": "<unknown>",
"ctx": {}
}
]
}Body
application/json
Was this page helpful?