Chat Completions
curl --request POST \
--url https://api.mor.org/api/v1/chat/completions \
--header 'Authorization: <authorization>' \
--header 'Content-Type: application/json' \
--data '
{
"messages": [
{
"role": "<string>",
"content": "<string>",
"name": "<string>",
"tool_calls": [
{}
],
"tool_call_id": "<string>"
}
],
"model": "<string>",
"temperature": 123,
"top_p": 123,
"n": 123,
"stream": true,
"stop": {},
"max_tokens": 123,
"presence_penalty": 123,
"frequency_penalty": 123,
"tools": [
{}
],
"tool_choice": {},
"session_id": "<string>"
}
'import requests
url = "https://api.mor.org/api/v1/chat/completions"
payload = {
"messages": [
{
"role": "<string>",
"content": "<string>",
"name": "<string>",
"tool_calls": [{}],
"tool_call_id": "<string>"
}
],
"model": "<string>",
"temperature": 123,
"top_p": 123,
"n": 123,
"stream": True,
"stop": {},
"max_tokens": 123,
"presence_penalty": 123,
"frequency_penalty": 123,
"tools": [{}],
"tool_choice": {},
"session_id": "<string>"
}
headers = {
"Authorization": "<authorization>",
"Content-Type": "application/json"
}
response = requests.post(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'POST',
headers: {Authorization: '<authorization>', 'Content-Type': 'application/json'},
body: JSON.stringify({
messages: [
{
role: '<string>',
content: '<string>',
name: '<string>',
tool_calls: [{}],
tool_call_id: '<string>'
}
],
model: '<string>',
temperature: 123,
top_p: 123,
n: 123,
stream: true,
stop: {},
max_tokens: 123,
presence_penalty: 123,
frequency_penalty: 123,
tools: [{}],
tool_choice: {},
session_id: '<string>'
})
};
fetch('https://api.mor.org/api/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.mor.org/api/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_calls' => [
[
]
],
'tool_call_id' => '<string>'
]
],
'model' => '<string>',
'temperature' => 123,
'top_p' => 123,
'n' => 123,
'stream' => true,
'stop' => [
],
'max_tokens' => 123,
'presence_penalty' => 123,
'frequency_penalty' => 123,
'tools' => [
[
]
],
'tool_choice' => [
],
'session_id' => '<string>'
]),
CURLOPT_HTTPHEADER => [
"Authorization: <authorization>",
"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.mor.org/api/v1/chat/completions"
payload := strings.NewReader("{\n \"messages\": [\n {\n \"role\": \"<string>\",\n \"content\": \"<string>\",\n \"name\": \"<string>\",\n \"tool_calls\": [\n {}\n ],\n \"tool_call_id\": \"<string>\"\n }\n ],\n \"model\": \"<string>\",\n \"temperature\": 123,\n \"top_p\": 123,\n \"n\": 123,\n \"stream\": true,\n \"stop\": {},\n \"max_tokens\": 123,\n \"presence_penalty\": 123,\n \"frequency_penalty\": 123,\n \"tools\": [\n {}\n ],\n \"tool_choice\": {},\n \"session_id\": \"<string>\"\n}")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("Authorization", "<authorization>")
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.mor.org/api/v1/chat/completions")
.header("Authorization", "<authorization>")
.header("Content-Type", "application/json")
.body("{\n \"messages\": [\n {\n \"role\": \"<string>\",\n \"content\": \"<string>\",\n \"name\": \"<string>\",\n \"tool_calls\": [\n {}\n ],\n \"tool_call_id\": \"<string>\"\n }\n ],\n \"model\": \"<string>\",\n \"temperature\": 123,\n \"top_p\": 123,\n \"n\": 123,\n \"stream\": true,\n \"stop\": {},\n \"max_tokens\": 123,\n \"presence_penalty\": 123,\n \"frequency_penalty\": 123,\n \"tools\": [\n {}\n ],\n \"tool_choice\": {},\n \"session_id\": \"<string>\"\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.mor.org/api/v1/chat/completions")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["Authorization"] = '<authorization>'
request["Content-Type"] = 'application/json'
request.body = "{\n \"messages\": [\n {\n \"role\": \"<string>\",\n \"content\": \"<string>\",\n \"name\": \"<string>\",\n \"tool_calls\": [\n {}\n ],\n \"tool_call_id\": \"<string>\"\n }\n ],\n \"model\": \"<string>\",\n \"temperature\": 123,\n \"top_p\": 123,\n \"n\": 123,\n \"stream\": true,\n \"stop\": {},\n \"max_tokens\": 123,\n \"presence_penalty\": 123,\n \"frequency_penalty\": 123,\n \"tools\": [\n {}\n ],\n \"tool_choice\": {},\n \"session_id\": \"<string>\"\n}"
response = http.request(request)
puts response.read_body{
"id": "<string>",
"object": "<string>",
"created": 123,
"model": "<string>",
"choices": [
{
"index": 123,
"message": {},
"finish_reason": "<string>"
}
],
"usage": {
"prompt_tokens": 123,
"completion_tokens": 123,
"total_tokens": 123
}
}Chat
Chat Completions
Create AI chat completions with OpenAI-compatible API
POST
/
api
/
v1
/
chat
/
completions
Chat Completions
curl --request POST \
--url https://api.mor.org/api/v1/chat/completions \
--header 'Authorization: <authorization>' \
--header 'Content-Type: application/json' \
--data '
{
"messages": [
{
"role": "<string>",
"content": "<string>",
"name": "<string>",
"tool_calls": [
{}
],
"tool_call_id": "<string>"
}
],
"model": "<string>",
"temperature": 123,
"top_p": 123,
"n": 123,
"stream": true,
"stop": {},
"max_tokens": 123,
"presence_penalty": 123,
"frequency_penalty": 123,
"tools": [
{}
],
"tool_choice": {},
"session_id": "<string>"
}
'import requests
url = "https://api.mor.org/api/v1/chat/completions"
payload = {
"messages": [
{
"role": "<string>",
"content": "<string>",
"name": "<string>",
"tool_calls": [{}],
"tool_call_id": "<string>"
}
],
"model": "<string>",
"temperature": 123,
"top_p": 123,
"n": 123,
"stream": True,
"stop": {},
"max_tokens": 123,
"presence_penalty": 123,
"frequency_penalty": 123,
"tools": [{}],
"tool_choice": {},
"session_id": "<string>"
}
headers = {
"Authorization": "<authorization>",
"Content-Type": "application/json"
}
response = requests.post(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'POST',
headers: {Authorization: '<authorization>', 'Content-Type': 'application/json'},
body: JSON.stringify({
messages: [
{
role: '<string>',
content: '<string>',
name: '<string>',
tool_calls: [{}],
tool_call_id: '<string>'
}
],
model: '<string>',
temperature: 123,
top_p: 123,
n: 123,
stream: true,
stop: {},
max_tokens: 123,
presence_penalty: 123,
frequency_penalty: 123,
tools: [{}],
tool_choice: {},
session_id: '<string>'
})
};
fetch('https://api.mor.org/api/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.mor.org/api/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_calls' => [
[
]
],
'tool_call_id' => '<string>'
]
],
'model' => '<string>',
'temperature' => 123,
'top_p' => 123,
'n' => 123,
'stream' => true,
'stop' => [
],
'max_tokens' => 123,
'presence_penalty' => 123,
'frequency_penalty' => 123,
'tools' => [
[
]
],
'tool_choice' => [
],
'session_id' => '<string>'
]),
CURLOPT_HTTPHEADER => [
"Authorization: <authorization>",
"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.mor.org/api/v1/chat/completions"
payload := strings.NewReader("{\n \"messages\": [\n {\n \"role\": \"<string>\",\n \"content\": \"<string>\",\n \"name\": \"<string>\",\n \"tool_calls\": [\n {}\n ],\n \"tool_call_id\": \"<string>\"\n }\n ],\n \"model\": \"<string>\",\n \"temperature\": 123,\n \"top_p\": 123,\n \"n\": 123,\n \"stream\": true,\n \"stop\": {},\n \"max_tokens\": 123,\n \"presence_penalty\": 123,\n \"frequency_penalty\": 123,\n \"tools\": [\n {}\n ],\n \"tool_choice\": {},\n \"session_id\": \"<string>\"\n}")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("Authorization", "<authorization>")
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.mor.org/api/v1/chat/completions")
.header("Authorization", "<authorization>")
.header("Content-Type", "application/json")
.body("{\n \"messages\": [\n {\n \"role\": \"<string>\",\n \"content\": \"<string>\",\n \"name\": \"<string>\",\n \"tool_calls\": [\n {}\n ],\n \"tool_call_id\": \"<string>\"\n }\n ],\n \"model\": \"<string>\",\n \"temperature\": 123,\n \"top_p\": 123,\n \"n\": 123,\n \"stream\": true,\n \"stop\": {},\n \"max_tokens\": 123,\n \"presence_penalty\": 123,\n \"frequency_penalty\": 123,\n \"tools\": [\n {}\n ],\n \"tool_choice\": {},\n \"session_id\": \"<string>\"\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.mor.org/api/v1/chat/completions")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["Authorization"] = '<authorization>'
request["Content-Type"] = 'application/json'
request.body = "{\n \"messages\": [\n {\n \"role\": \"<string>\",\n \"content\": \"<string>\",\n \"name\": \"<string>\",\n \"tool_calls\": [\n {}\n ],\n \"tool_call_id\": \"<string>\"\n }\n ],\n \"model\": \"<string>\",\n \"temperature\": 123,\n \"top_p\": 123,\n \"n\": 123,\n \"stream\": true,\n \"stop\": {},\n \"max_tokens\": 123,\n \"presence_penalty\": 123,\n \"frequency_penalty\": 123,\n \"tools\": [\n {}\n ],\n \"tool_choice\": {},\n \"session_id\": \"<string>\"\n}"
response = http.request(request)
puts response.read_body{
"id": "<string>",
"object": "<string>",
"created": 123,
"model": "<string>",
"choices": [
{
"index": 123,
"message": {},
"finish_reason": "<string>"
}
],
"usage": {
"prompt_tokens": 123,
"completion_tokens": 123,
"total_tokens": 123
}
}Create a chat completion with automatic session creation if enabled.
Supports both streaming and non-streaming responses based on the
stream parameter. Tool calling is supported but may work better with streaming enabled.
Headers
string
required
API key in format:
Bearer sk-xxxxxxBody
array
required
Array of message objects representing the conversation
string
Model ID to use for completion (blockchain hex address or name)
number
default:1
Sampling temperature between 0 and 2. Higher values make output more random.
number
default:1
Nucleus sampling parameter. Alternative to temperature.
integer
default:1
Number of completions to generate
boolean
default:false
Whether to stream the response as server-sent events
string | array
Up to 4 sequences where the API will stop generating
integer
Maximum number of tokens to generate
number
default:0
Number between -2.0 and 2.0. Positive values penalize new tokens based on whether they appear in the text so far.
number
default:0
Number between -2.0 and 2.0. Positive values penalize new tokens based on their frequency in the text so far.
array
List of tools the model can call
string | object
Controls which tool is called by the model
string
Optional session ID to use. If not provided, uses the session associated with the API key.
Response
string
Unique completion ID
string
Always “chat.completion”
integer
Unix timestamp of completion creation
string
Model used for the completion
array
object
The API is fully compatible with the OpenAI SDK. Simply change the
base_url to point to the Morpheus Gateway.Streaming responses return server-sent events. Set
stream: true in your request to enable streaming.⌘I

