curl --request POST \
--url https://api.dev.swarmd.ai/relay/llm/v1/{gatewayId}/chat/completions \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '
{
"messages": [
{
"role": "<string>",
"content": "<unknown>",
"name": "<string>",
"tool_calls": [
{
"id": "<string>",
"type": "<string>",
"function": {
"name": "<string>",
"arguments": "<string>"
}
}
],
"tool_call_id": "<string>",
"refusal": "<string>"
}
],
"model": "<string>",
"temperature": 123,
"max_tokens": 123,
"top_p": 123,
"stream": true,
"metadata": {},
"tools": [
{
"type": "<string>",
"function": {
"name": "<string>",
"description": "<string>",
"parameters": "<unknown>"
}
}
],
"tool_choice": "<unknown>",
"response_format": "<unknown>",
"parallel_tool_calls": true,
"seed": 123
}
'import requests
url = "https://api.dev.swarmd.ai/relay/llm/v1/{gatewayId}/chat/completions"
payload = {
"messages": [
{
"role": "<string>",
"content": "<unknown>",
"name": "<string>",
"tool_calls": [
{
"id": "<string>",
"type": "<string>",
"function": {
"name": "<string>",
"arguments": "<string>"
}
}
],
"tool_call_id": "<string>",
"refusal": "<string>"
}
],
"model": "<string>",
"temperature": 123,
"max_tokens": 123,
"top_p": 123,
"stream": True,
"metadata": {},
"tools": [
{
"type": "<string>",
"function": {
"name": "<string>",
"description": "<string>",
"parameters": "<unknown>"
}
}
],
"tool_choice": "<unknown>",
"response_format": "<unknown>",
"parallel_tool_calls": True,
"seed": 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: '<unknown>',
name: '<string>',
tool_calls: [
{
id: '<string>',
type: '<string>',
function: {name: '<string>', arguments: '<string>'}
}
],
tool_call_id: '<string>',
refusal: '<string>'
}
],
model: '<string>',
temperature: 123,
max_tokens: 123,
top_p: 123,
stream: true,
metadata: {},
tools: [
{
type: '<string>',
function: {name: '<string>', description: '<string>', parameters: '<unknown>'}
}
],
tool_choice: '<unknown>',
response_format: '<unknown>',
parallel_tool_calls: true,
seed: 123
})
};
fetch('https://api.dev.swarmd.ai/relay/llm/v1/{gatewayId}/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.dev.swarmd.ai/relay/llm/v1/{gatewayId}/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' => '<unknown>',
'name' => '<string>',
'tool_calls' => [
[
'id' => '<string>',
'type' => '<string>',
'function' => [
'name' => '<string>',
'arguments' => '<string>'
]
]
],
'tool_call_id' => '<string>',
'refusal' => '<string>'
]
],
'model' => '<string>',
'temperature' => 123,
'max_tokens' => 123,
'top_p' => 123,
'stream' => true,
'metadata' => [
],
'tools' => [
[
'type' => '<string>',
'function' => [
'name' => '<string>',
'description' => '<string>',
'parameters' => '<unknown>'
]
]
],
'tool_choice' => '<unknown>',
'response_format' => '<unknown>',
'parallel_tool_calls' => true,
'seed' => 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://api.dev.swarmd.ai/relay/llm/v1/{gatewayId}/chat/completions"
payload := strings.NewReader("{\n \"messages\": [\n {\n \"role\": \"<string>\",\n \"content\": \"<unknown>\",\n \"name\": \"<string>\",\n \"tool_calls\": [\n {\n \"id\": \"<string>\",\n \"type\": \"<string>\",\n \"function\": {\n \"name\": \"<string>\",\n \"arguments\": \"<string>\"\n }\n }\n ],\n \"tool_call_id\": \"<string>\",\n \"refusal\": \"<string>\"\n }\n ],\n \"model\": \"<string>\",\n \"temperature\": 123,\n \"max_tokens\": 123,\n \"top_p\": 123,\n \"stream\": true,\n \"metadata\": {},\n \"tools\": [\n {\n \"type\": \"<string>\",\n \"function\": {\n \"name\": \"<string>\",\n \"description\": \"<string>\",\n \"parameters\": \"<unknown>\"\n }\n }\n ],\n \"tool_choice\": \"<unknown>\",\n \"response_format\": \"<unknown>\",\n \"parallel_tool_calls\": true,\n \"seed\": 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://api.dev.swarmd.ai/relay/llm/v1/{gatewayId}/chat/completions")
.header("Authorization", "Bearer <token>")
.header("Content-Type", "application/json")
.body("{\n \"messages\": [\n {\n \"role\": \"<string>\",\n \"content\": \"<unknown>\",\n \"name\": \"<string>\",\n \"tool_calls\": [\n {\n \"id\": \"<string>\",\n \"type\": \"<string>\",\n \"function\": {\n \"name\": \"<string>\",\n \"arguments\": \"<string>\"\n }\n }\n ],\n \"tool_call_id\": \"<string>\",\n \"refusal\": \"<string>\"\n }\n ],\n \"model\": \"<string>\",\n \"temperature\": 123,\n \"max_tokens\": 123,\n \"top_p\": 123,\n \"stream\": true,\n \"metadata\": {},\n \"tools\": [\n {\n \"type\": \"<string>\",\n \"function\": {\n \"name\": \"<string>\",\n \"description\": \"<string>\",\n \"parameters\": \"<unknown>\"\n }\n }\n ],\n \"tool_choice\": \"<unknown>\",\n \"response_format\": \"<unknown>\",\n \"parallel_tool_calls\": true,\n \"seed\": 123\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.dev.swarmd.ai/relay/llm/v1/{gatewayId}/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\": \"<unknown>\",\n \"name\": \"<string>\",\n \"tool_calls\": [\n {\n \"id\": \"<string>\",\n \"type\": \"<string>\",\n \"function\": {\n \"name\": \"<string>\",\n \"arguments\": \"<string>\"\n }\n }\n ],\n \"tool_call_id\": \"<string>\",\n \"refusal\": \"<string>\"\n }\n ],\n \"model\": \"<string>\",\n \"temperature\": 123,\n \"max_tokens\": 123,\n \"top_p\": 123,\n \"stream\": true,\n \"metadata\": {},\n \"tools\": [\n {\n \"type\": \"<string>\",\n \"function\": {\n \"name\": \"<string>\",\n \"description\": \"<string>\",\n \"parameters\": \"<unknown>\"\n }\n }\n ],\n \"tool_choice\": \"<unknown>\",\n \"response_format\": \"<unknown>\",\n \"parallel_tool_calls\": true,\n \"seed\": 123\n}"
response = http.request(request)
puts response.read_body{}OpenAI-compatible chat-completions endpoint routed through an LLM gateway
Security Requirements
| Auth Types | Entities | Permissions | Required Roles |
|---|---|---|---|
| AGENT, USER | LLM_GATEWAY | READ | LLM_GATEWAY:READ |
Tenant is derived from the authenticated principal — callers do not pass it in the URL. The principal (user or agent) must hold an active subscription on the target gateway; RBAC alone is not sufficient. Callers SHOULD propagate the swarmd correlation id via the X-Correlation-Id header so the LLM call is stitched to the inbound agent task in audit traces. If the header is absent the gateway generates one.
curl --request POST \
--url https://api.dev.swarmd.ai/relay/llm/v1/{gatewayId}/chat/completions \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '
{
"messages": [
{
"role": "<string>",
"content": "<unknown>",
"name": "<string>",
"tool_calls": [
{
"id": "<string>",
"type": "<string>",
"function": {
"name": "<string>",
"arguments": "<string>"
}
}
],
"tool_call_id": "<string>",
"refusal": "<string>"
}
],
"model": "<string>",
"temperature": 123,
"max_tokens": 123,
"top_p": 123,
"stream": true,
"metadata": {},
"tools": [
{
"type": "<string>",
"function": {
"name": "<string>",
"description": "<string>",
"parameters": "<unknown>"
}
}
],
"tool_choice": "<unknown>",
"response_format": "<unknown>",
"parallel_tool_calls": true,
"seed": 123
}
'import requests
url = "https://api.dev.swarmd.ai/relay/llm/v1/{gatewayId}/chat/completions"
payload = {
"messages": [
{
"role": "<string>",
"content": "<unknown>",
"name": "<string>",
"tool_calls": [
{
"id": "<string>",
"type": "<string>",
"function": {
"name": "<string>",
"arguments": "<string>"
}
}
],
"tool_call_id": "<string>",
"refusal": "<string>"
}
],
"model": "<string>",
"temperature": 123,
"max_tokens": 123,
"top_p": 123,
"stream": True,
"metadata": {},
"tools": [
{
"type": "<string>",
"function": {
"name": "<string>",
"description": "<string>",
"parameters": "<unknown>"
}
}
],
"tool_choice": "<unknown>",
"response_format": "<unknown>",
"parallel_tool_calls": True,
"seed": 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: '<unknown>',
name: '<string>',
tool_calls: [
{
id: '<string>',
type: '<string>',
function: {name: '<string>', arguments: '<string>'}
}
],
tool_call_id: '<string>',
refusal: '<string>'
}
],
model: '<string>',
temperature: 123,
max_tokens: 123,
top_p: 123,
stream: true,
metadata: {},
tools: [
{
type: '<string>',
function: {name: '<string>', description: '<string>', parameters: '<unknown>'}
}
],
tool_choice: '<unknown>',
response_format: '<unknown>',
parallel_tool_calls: true,
seed: 123
})
};
fetch('https://api.dev.swarmd.ai/relay/llm/v1/{gatewayId}/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.dev.swarmd.ai/relay/llm/v1/{gatewayId}/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' => '<unknown>',
'name' => '<string>',
'tool_calls' => [
[
'id' => '<string>',
'type' => '<string>',
'function' => [
'name' => '<string>',
'arguments' => '<string>'
]
]
],
'tool_call_id' => '<string>',
'refusal' => '<string>'
]
],
'model' => '<string>',
'temperature' => 123,
'max_tokens' => 123,
'top_p' => 123,
'stream' => true,
'metadata' => [
],
'tools' => [
[
'type' => '<string>',
'function' => [
'name' => '<string>',
'description' => '<string>',
'parameters' => '<unknown>'
]
]
],
'tool_choice' => '<unknown>',
'response_format' => '<unknown>',
'parallel_tool_calls' => true,
'seed' => 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://api.dev.swarmd.ai/relay/llm/v1/{gatewayId}/chat/completions"
payload := strings.NewReader("{\n \"messages\": [\n {\n \"role\": \"<string>\",\n \"content\": \"<unknown>\",\n \"name\": \"<string>\",\n \"tool_calls\": [\n {\n \"id\": \"<string>\",\n \"type\": \"<string>\",\n \"function\": {\n \"name\": \"<string>\",\n \"arguments\": \"<string>\"\n }\n }\n ],\n \"tool_call_id\": \"<string>\",\n \"refusal\": \"<string>\"\n }\n ],\n \"model\": \"<string>\",\n \"temperature\": 123,\n \"max_tokens\": 123,\n \"top_p\": 123,\n \"stream\": true,\n \"metadata\": {},\n \"tools\": [\n {\n \"type\": \"<string>\",\n \"function\": {\n \"name\": \"<string>\",\n \"description\": \"<string>\",\n \"parameters\": \"<unknown>\"\n }\n }\n ],\n \"tool_choice\": \"<unknown>\",\n \"response_format\": \"<unknown>\",\n \"parallel_tool_calls\": true,\n \"seed\": 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://api.dev.swarmd.ai/relay/llm/v1/{gatewayId}/chat/completions")
.header("Authorization", "Bearer <token>")
.header("Content-Type", "application/json")
.body("{\n \"messages\": [\n {\n \"role\": \"<string>\",\n \"content\": \"<unknown>\",\n \"name\": \"<string>\",\n \"tool_calls\": [\n {\n \"id\": \"<string>\",\n \"type\": \"<string>\",\n \"function\": {\n \"name\": \"<string>\",\n \"arguments\": \"<string>\"\n }\n }\n ],\n \"tool_call_id\": \"<string>\",\n \"refusal\": \"<string>\"\n }\n ],\n \"model\": \"<string>\",\n \"temperature\": 123,\n \"max_tokens\": 123,\n \"top_p\": 123,\n \"stream\": true,\n \"metadata\": {},\n \"tools\": [\n {\n \"type\": \"<string>\",\n \"function\": {\n \"name\": \"<string>\",\n \"description\": \"<string>\",\n \"parameters\": \"<unknown>\"\n }\n }\n ],\n \"tool_choice\": \"<unknown>\",\n \"response_format\": \"<unknown>\",\n \"parallel_tool_calls\": true,\n \"seed\": 123\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.dev.swarmd.ai/relay/llm/v1/{gatewayId}/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\": \"<unknown>\",\n \"name\": \"<string>\",\n \"tool_calls\": [\n {\n \"id\": \"<string>\",\n \"type\": \"<string>\",\n \"function\": {\n \"name\": \"<string>\",\n \"arguments\": \"<string>\"\n }\n }\n ],\n \"tool_call_id\": \"<string>\",\n \"refusal\": \"<string>\"\n }\n ],\n \"model\": \"<string>\",\n \"temperature\": 123,\n \"max_tokens\": 123,\n \"top_p\": 123,\n \"stream\": true,\n \"metadata\": {},\n \"tools\": [\n {\n \"type\": \"<string>\",\n \"function\": {\n \"name\": \"<string>\",\n \"description\": \"<string>\",\n \"parameters\": \"<unknown>\"\n }\n }\n ],\n \"tool_choice\": \"<unknown>\",\n \"response_format\": \"<unknown>\",\n \"parallel_tool_calls\": true,\n \"seed\": 123\n}"
response = http.request(request)
puts response.read_body{}Authorizations
JWT token (USER, AGENT, or SERVICE auth)
Headers
Swarmd correlation id stitched into audit events. The MdcLoggingFilter extracts it from this header (or generates a UUID when absent) and the chain propagates it onto every emitted audit event so multi-agent + multi-LLM workloads are joined by a single id.
Path Parameters
Body
1Show child attributes
Show child attributes
Show child attributes
Show child attributes
Show child attributes
Show child attributes
Response
OK
The response is of type object.
