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
API key in format:
Bearer sk-xxxxxxBody
Array of message objects representing the conversation
Show Message Object
Show Message Object
Role of the message author:
system, user, assistant, or toolContent of the message
Name of the author (optional)
Tool calls made by the assistant (for assistant messages)
ID of the tool call this message is responding to (for tool messages)
Model ID to use for completion (blockchain hex address or name)
Sampling temperature between 0 and 2. Higher values make output more random.
Nucleus sampling parameter. Alternative to temperature.
Number of completions to generate
Whether to stream the response as server-sent events
Up to 4 sequences where the API will stop generating
Maximum number of tokens to generate
Number between -2.0 and 2.0. Positive values penalize new tokens based on whether they appear in the text so far.
Number between -2.0 and 2.0. Positive values penalize new tokens based on their frequency in the text so far.
List of tools the model can call
Controls which tool is called by the model
Optional session ID to use. If not provided, uses the session associated with the API key.
Response
Unique completion ID
Always “chat.completion”
Unix timestamp of completion creation
Model used for the completion
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

