Create a response (OpenAI-compatible, non-streaming)
curl --request POST \
--url https://api.swarms.world/v1/responses \
--header 'Content-Type: application/json' \
--header 'x-api-key: <x-api-key>' \
--data '
{
"model": "<string>",
"input": "<string>",
"instructions": "<string>",
"max_output_tokens": 2,
"temperature": 1,
"top_p": 123
}
'import requests
url = "https://api.swarms.world/v1/responses"
payload = {
"model": "<string>",
"input": "<string>",
"instructions": "<string>",
"max_output_tokens": 2,
"temperature": 1,
"top_p": 123
}
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>',
input: '<string>',
instructions: '<string>',
max_output_tokens: 2,
temperature: 1,
top_p: 123
})
};
fetch('https://api.swarms.world/v1/responses', 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/responses",
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>',
'input' => '<string>',
'instructions' => '<string>',
'max_output_tokens' => 2,
'temperature' => 1,
'top_p' => 123
]),
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/responses"
payload := strings.NewReader("{\n \"model\": \"<string>\",\n \"input\": \"<string>\",\n \"instructions\": \"<string>\",\n \"max_output_tokens\": 2,\n \"temperature\": 1,\n \"top_p\": 123\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/responses")
.header("x-api-key", "<x-api-key>")
.header("Content-Type", "application/json")
.body("{\n \"model\": \"<string>\",\n \"input\": \"<string>\",\n \"instructions\": \"<string>\",\n \"max_output_tokens\": 2,\n \"temperature\": 1,\n \"top_p\": 123\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.swarms.world/v1/responses")
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 \"input\": \"<string>\",\n \"instructions\": \"<string>\",\n \"max_output_tokens\": 2,\n \"temperature\": 1,\n \"top_p\": 123\n}"
response = http.request(request)
puts response.read_body{
"id": "<string>",
"created_at": 123,
"model": "<string>",
"status": "completed",
"output": [
{
"id": "<string>",
"status": "completed",
"content": [
{
"text": "<string>",
"type": "output_text",
"annotations": [
"<unknown>"
]
}
],
"type": "message",
"role": "assistant"
}
],
"usage": {
"input_tokens": 123,
"output_tokens": 123,
"total_tokens": 123,
"input_tokens_details": {
"cached_tokens": 0
},
"output_tokens_details": {
"reasoning_tokens": 0
}
},
"object": "response",
"incomplete_details": {
"reason": "max_output_tokens"
},
"error": null
}{
"error": {
"message": "<string>",
"type": "<string>",
"code": "<string>",
"param": "<string>"
}
}{
"error": {
"message": "<string>",
"type": "<string>",
"code": "<string>",
"param": "<string>"
}
}{
"detail": [
{
"loc": [
"<string>"
],
"msg": "<string>",
"type": "<string>",
"input": "<unknown>",
"ctx": {}
}
]
}OpenAI Compatible
Create a response (OpenAI-compatible, non-streaming)
Creates a standard (non-streaming) completion response, compatible with the OpenAI response format. Use this endpoint as a drop-in replacement to create responses similar to OpenAI’s chat/completions, but always returns the full response in a single payload. Requires API key authentication and is subject to rate limiting. Common use cases include chatbot interactions, assistant replies, and single-turn LLM completions.
POST
/
v1
/
responses
Create a response (OpenAI-compatible, non-streaming)
curl --request POST \
--url https://api.swarms.world/v1/responses \
--header 'Content-Type: application/json' \
--header 'x-api-key: <x-api-key>' \
--data '
{
"model": "<string>",
"input": "<string>",
"instructions": "<string>",
"max_output_tokens": 2,
"temperature": 1,
"top_p": 123
}
'import requests
url = "https://api.swarms.world/v1/responses"
payload = {
"model": "<string>",
"input": "<string>",
"instructions": "<string>",
"max_output_tokens": 2,
"temperature": 1,
"top_p": 123
}
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>',
input: '<string>',
instructions: '<string>',
max_output_tokens: 2,
temperature: 1,
top_p: 123
})
};
fetch('https://api.swarms.world/v1/responses', 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/responses",
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>',
'input' => '<string>',
'instructions' => '<string>',
'max_output_tokens' => 2,
'temperature' => 1,
'top_p' => 123
]),
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/responses"
payload := strings.NewReader("{\n \"model\": \"<string>\",\n \"input\": \"<string>\",\n \"instructions\": \"<string>\",\n \"max_output_tokens\": 2,\n \"temperature\": 1,\n \"top_p\": 123\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/responses")
.header("x-api-key", "<x-api-key>")
.header("Content-Type", "application/json")
.body("{\n \"model\": \"<string>\",\n \"input\": \"<string>\",\n \"instructions\": \"<string>\",\n \"max_output_tokens\": 2,\n \"temperature\": 1,\n \"top_p\": 123\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.swarms.world/v1/responses")
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 \"input\": \"<string>\",\n \"instructions\": \"<string>\",\n \"max_output_tokens\": 2,\n \"temperature\": 1,\n \"top_p\": 123\n}"
response = http.request(request)
puts response.read_body{
"id": "<string>",
"created_at": 123,
"model": "<string>",
"status": "completed",
"output": [
{
"id": "<string>",
"status": "completed",
"content": [
{
"text": "<string>",
"type": "output_text",
"annotations": [
"<unknown>"
]
}
],
"type": "message",
"role": "assistant"
}
],
"usage": {
"input_tokens": 123,
"output_tokens": 123,
"total_tokens": 123,
"input_tokens_details": {
"cached_tokens": 0
},
"output_tokens_details": {
"reasoning_tokens": 0
}
},
"object": "response",
"incomplete_details": {
"reason": "max_output_tokens"
},
"error": null
}{
"error": {
"message": "<string>",
"type": "<string>",
"code": "<string>",
"param": "<string>"
}
}{
"error": {
"message": "<string>",
"type": "<string>",
"code": "<string>",
"param": "<string>"
}
}{
"detail": [
{
"loc": [
"<string>"
],
"msg": "<string>",
"type": "<string>",
"input": "<unknown>",
"ctx": {}
}
]
}Body
application/json
Request body for POST /v1/responses. Any other field set to a non-empty value, such as stream, tools or previous_response_id, returns 400 until it is supported.
Response
Successful Response
A completed or incomplete response, in the OpenAI Responses API shape.
Was this page helpful?