curl --request POST \
--url https://api.openmodex.com/v1/chat/completions \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '
{
"model": "<string>",
"messages": [
{
"content": "<string>",
"name": "<string>",
"tool_call_id": "<string>",
"tool_calls": [
{
"id": "<string>",
"type": "function",
"function": {
"name": "<string>",
"arguments": "<string>"
}
}
]
}
],
"stream": false,
"temperature": 1,
"top_p": 123,
"n": 123,
"max_tokens": 123,
"stop": "<string>",
"frequency_penalty": 0,
"presence_penalty": 0,
"logit_bias": {},
"tools": [
{
"type": "function",
"function": {
"name": "<string>",
"description": "<string>",
"parameters": {}
}
}
],
"tool_choice": "<string>",
"response_format": {
"type": "<string>"
},
"seed": 123,
"user": "<string>",
"routing": {
"strategy": "<string>",
"fallback": [
"<string>"
],
"allow_upgrade": true
},
"cache": {
"enabled": true,
"ttl": 123
}
}
'import requests
url = "https://api.openmodex.com/v1/chat/completions"
payload = {
"model": "<string>",
"messages": [
{
"content": "<string>",
"name": "<string>",
"tool_call_id": "<string>",
"tool_calls": [
{
"id": "<string>",
"type": "function",
"function": {
"name": "<string>",
"arguments": "<string>"
}
}
]
}
],
"stream": False,
"temperature": 1,
"top_p": 123,
"n": 123,
"max_tokens": 123,
"stop": "<string>",
"frequency_penalty": 0,
"presence_penalty": 0,
"logit_bias": {},
"tools": [
{
"type": "function",
"function": {
"name": "<string>",
"description": "<string>",
"parameters": {}
}
}
],
"tool_choice": "<string>",
"response_format": { "type": "<string>" },
"seed": 123,
"user": "<string>",
"routing": {
"strategy": "<string>",
"fallback": ["<string>"],
"allow_upgrade": True
},
"cache": {
"enabled": True,
"ttl": 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({
model: '<string>',
messages: [
{
content: '<string>',
name: '<string>',
tool_call_id: '<string>',
tool_calls: [
{
id: '<string>',
type: 'function',
function: {name: '<string>', arguments: '<string>'}
}
]
}
],
stream: false,
temperature: 1,
top_p: 123,
n: 123,
max_tokens: 123,
stop: '<string>',
frequency_penalty: 0,
presence_penalty: 0,
logit_bias: {},
tools: [
{
type: 'function',
function: {name: '<string>', description: '<string>', parameters: {}}
}
],
tool_choice: '<string>',
response_format: {type: '<string>'},
seed: 123,
user: '<string>',
routing: {strategy: '<string>', fallback: ['<string>'], allow_upgrade: true},
cache: {enabled: true, ttl: 123}
})
};
fetch('https://api.openmodex.com/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.openmodex.com/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_call_id' => '<string>',
'tool_calls' => [
[
'id' => '<string>',
'type' => 'function',
'function' => [
'name' => '<string>',
'arguments' => '<string>'
]
]
]
]
],
'stream' => false,
'temperature' => 1,
'top_p' => 123,
'n' => 123,
'max_tokens' => 123,
'stop' => '<string>',
'frequency_penalty' => 0,
'presence_penalty' => 0,
'logit_bias' => [
],
'tools' => [
[
'type' => 'function',
'function' => [
'name' => '<string>',
'description' => '<string>',
'parameters' => [
]
]
]
],
'tool_choice' => '<string>',
'response_format' => [
'type' => '<string>'
],
'seed' => 123,
'user' => '<string>',
'routing' => [
'strategy' => '<string>',
'fallback' => [
'<string>'
],
'allow_upgrade' => true
],
'cache' => [
'enabled' => true,
'ttl' => 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.openmodex.com/v1/chat/completions"
payload := strings.NewReader("{\n \"model\": \"<string>\",\n \"messages\": [\n {\n \"content\": \"<string>\",\n \"name\": \"<string>\",\n \"tool_call_id\": \"<string>\",\n \"tool_calls\": [\n {\n \"id\": \"<string>\",\n \"type\": \"function\",\n \"function\": {\n \"name\": \"<string>\",\n \"arguments\": \"<string>\"\n }\n }\n ]\n }\n ],\n \"stream\": false,\n \"temperature\": 1,\n \"top_p\": 123,\n \"n\": 123,\n \"max_tokens\": 123,\n \"stop\": \"<string>\",\n \"frequency_penalty\": 0,\n \"presence_penalty\": 0,\n \"logit_bias\": {},\n \"tools\": [\n {\n \"type\": \"function\",\n \"function\": {\n \"name\": \"<string>\",\n \"description\": \"<string>\",\n \"parameters\": {}\n }\n }\n ],\n \"tool_choice\": \"<string>\",\n \"response_format\": {\n \"type\": \"<string>\"\n },\n \"seed\": 123,\n \"user\": \"<string>\",\n \"routing\": {\n \"strategy\": \"<string>\",\n \"fallback\": [\n \"<string>\"\n ],\n \"allow_upgrade\": true\n },\n \"cache\": {\n \"enabled\": true,\n \"ttl\": 123\n }\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.openmodex.com/v1/chat/completions")
.header("Authorization", "Bearer <token>")
.header("Content-Type", "application/json")
.body("{\n \"model\": \"<string>\",\n \"messages\": [\n {\n \"content\": \"<string>\",\n \"name\": \"<string>\",\n \"tool_call_id\": \"<string>\",\n \"tool_calls\": [\n {\n \"id\": \"<string>\",\n \"type\": \"function\",\n \"function\": {\n \"name\": \"<string>\",\n \"arguments\": \"<string>\"\n }\n }\n ]\n }\n ],\n \"stream\": false,\n \"temperature\": 1,\n \"top_p\": 123,\n \"n\": 123,\n \"max_tokens\": 123,\n \"stop\": \"<string>\",\n \"frequency_penalty\": 0,\n \"presence_penalty\": 0,\n \"logit_bias\": {},\n \"tools\": [\n {\n \"type\": \"function\",\n \"function\": {\n \"name\": \"<string>\",\n \"description\": \"<string>\",\n \"parameters\": {}\n }\n }\n ],\n \"tool_choice\": \"<string>\",\n \"response_format\": {\n \"type\": \"<string>\"\n },\n \"seed\": 123,\n \"user\": \"<string>\",\n \"routing\": {\n \"strategy\": \"<string>\",\n \"fallback\": [\n \"<string>\"\n ],\n \"allow_upgrade\": true\n },\n \"cache\": {\n \"enabled\": true,\n \"ttl\": 123\n }\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.openmodex.com/v1/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 \"model\": \"<string>\",\n \"messages\": [\n {\n \"content\": \"<string>\",\n \"name\": \"<string>\",\n \"tool_call_id\": \"<string>\",\n \"tool_calls\": [\n {\n \"id\": \"<string>\",\n \"type\": \"function\",\n \"function\": {\n \"name\": \"<string>\",\n \"arguments\": \"<string>\"\n }\n }\n ]\n }\n ],\n \"stream\": false,\n \"temperature\": 1,\n \"top_p\": 123,\n \"n\": 123,\n \"max_tokens\": 123,\n \"stop\": \"<string>\",\n \"frequency_penalty\": 0,\n \"presence_penalty\": 0,\n \"logit_bias\": {},\n \"tools\": [\n {\n \"type\": \"function\",\n \"function\": {\n \"name\": \"<string>\",\n \"description\": \"<string>\",\n \"parameters\": {}\n }\n }\n ],\n \"tool_choice\": \"<string>\",\n \"response_format\": {\n \"type\": \"<string>\"\n },\n \"seed\": 123,\n \"user\": \"<string>\",\n \"routing\": {\n \"strategy\": \"<string>\",\n \"fallback\": [\n \"<string>\"\n ],\n \"allow_upgrade\": true\n },\n \"cache\": {\n \"enabled\": true,\n \"ttl\": 123\n }\n}"
response = http.request(request)
puts response.read_body{
"id": "<string>",
"object": "chat.completion",
"created": 123,
"model": "<string>",
"choices": [
{
"index": 123,
"message": {
"role": "<string>",
"content": "<string>",
"tool_calls": [
{
"id": "<string>",
"type": "function",
"function": {
"name": "<string>",
"arguments": "<string>"
}
}
]
},
"finish_reason": "stop"
}
],
"usage": {
"prompt_tokens": 123,
"completion_tokens": 123,
"total_tokens": 123,
"cost_usd": 123
},
"system_fingerprint": "<string>",
"openmodex": {
"request_id": "<string>",
"model_used": "<string>",
"provider": "<string>",
"cache_hit": true,
"routing_strategy": "<string>",
"fallback_used": true,
"latency_ms": 123
}
}{
"error": {
"message": "<string>",
"type": "<string>",
"code": "<string>"
}
}{
"error": {
"message": "<string>",
"type": "<string>",
"code": "<string>"
}
}{
"error": {
"message": "<string>",
"type": "<string>",
"code": "<string>"
}
}{
"error": {
"message": "<string>",
"type": "<string>",
"code": "<string>"
}
}{
"error": {
"message": "<string>",
"type": "<string>",
"code": "<string>"
}
}{
"error": {
"message": "<string>",
"type": "<string>",
"code": "<string>"
}
}{
"error": {
"message": "<string>",
"type": "<string>",
"code": "<string>"
}
}{
"error": {
"message": "<string>",
"type": "<string>",
"code": "<string>"
}
}建立聊天補全
POST /v1/chat/completions — 為對話建立模型回應。
curl --request POST \
--url https://api.openmodex.com/v1/chat/completions \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '
{
"model": "<string>",
"messages": [
{
"content": "<string>",
"name": "<string>",
"tool_call_id": "<string>",
"tool_calls": [
{
"id": "<string>",
"type": "function",
"function": {
"name": "<string>",
"arguments": "<string>"
}
}
]
}
],
"stream": false,
"temperature": 1,
"top_p": 123,
"n": 123,
"max_tokens": 123,
"stop": "<string>",
"frequency_penalty": 0,
"presence_penalty": 0,
"logit_bias": {},
"tools": [
{
"type": "function",
"function": {
"name": "<string>",
"description": "<string>",
"parameters": {}
}
}
],
"tool_choice": "<string>",
"response_format": {
"type": "<string>"
},
"seed": 123,
"user": "<string>",
"routing": {
"strategy": "<string>",
"fallback": [
"<string>"
],
"allow_upgrade": true
},
"cache": {
"enabled": true,
"ttl": 123
}
}
'import requests
url = "https://api.openmodex.com/v1/chat/completions"
payload = {
"model": "<string>",
"messages": [
{
"content": "<string>",
"name": "<string>",
"tool_call_id": "<string>",
"tool_calls": [
{
"id": "<string>",
"type": "function",
"function": {
"name": "<string>",
"arguments": "<string>"
}
}
]
}
],
"stream": False,
"temperature": 1,
"top_p": 123,
"n": 123,
"max_tokens": 123,
"stop": "<string>",
"frequency_penalty": 0,
"presence_penalty": 0,
"logit_bias": {},
"tools": [
{
"type": "function",
"function": {
"name": "<string>",
"description": "<string>",
"parameters": {}
}
}
],
"tool_choice": "<string>",
"response_format": { "type": "<string>" },
"seed": 123,
"user": "<string>",
"routing": {
"strategy": "<string>",
"fallback": ["<string>"],
"allow_upgrade": True
},
"cache": {
"enabled": True,
"ttl": 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({
model: '<string>',
messages: [
{
content: '<string>',
name: '<string>',
tool_call_id: '<string>',
tool_calls: [
{
id: '<string>',
type: 'function',
function: {name: '<string>', arguments: '<string>'}
}
]
}
],
stream: false,
temperature: 1,
top_p: 123,
n: 123,
max_tokens: 123,
stop: '<string>',
frequency_penalty: 0,
presence_penalty: 0,
logit_bias: {},
tools: [
{
type: 'function',
function: {name: '<string>', description: '<string>', parameters: {}}
}
],
tool_choice: '<string>',
response_format: {type: '<string>'},
seed: 123,
user: '<string>',
routing: {strategy: '<string>', fallback: ['<string>'], allow_upgrade: true},
cache: {enabled: true, ttl: 123}
})
};
fetch('https://api.openmodex.com/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.openmodex.com/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_call_id' => '<string>',
'tool_calls' => [
[
'id' => '<string>',
'type' => 'function',
'function' => [
'name' => '<string>',
'arguments' => '<string>'
]
]
]
]
],
'stream' => false,
'temperature' => 1,
'top_p' => 123,
'n' => 123,
'max_tokens' => 123,
'stop' => '<string>',
'frequency_penalty' => 0,
'presence_penalty' => 0,
'logit_bias' => [
],
'tools' => [
[
'type' => 'function',
'function' => [
'name' => '<string>',
'description' => '<string>',
'parameters' => [
]
]
]
],
'tool_choice' => '<string>',
'response_format' => [
'type' => '<string>'
],
'seed' => 123,
'user' => '<string>',
'routing' => [
'strategy' => '<string>',
'fallback' => [
'<string>'
],
'allow_upgrade' => true
],
'cache' => [
'enabled' => true,
'ttl' => 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.openmodex.com/v1/chat/completions"
payload := strings.NewReader("{\n \"model\": \"<string>\",\n \"messages\": [\n {\n \"content\": \"<string>\",\n \"name\": \"<string>\",\n \"tool_call_id\": \"<string>\",\n \"tool_calls\": [\n {\n \"id\": \"<string>\",\n \"type\": \"function\",\n \"function\": {\n \"name\": \"<string>\",\n \"arguments\": \"<string>\"\n }\n }\n ]\n }\n ],\n \"stream\": false,\n \"temperature\": 1,\n \"top_p\": 123,\n \"n\": 123,\n \"max_tokens\": 123,\n \"stop\": \"<string>\",\n \"frequency_penalty\": 0,\n \"presence_penalty\": 0,\n \"logit_bias\": {},\n \"tools\": [\n {\n \"type\": \"function\",\n \"function\": {\n \"name\": \"<string>\",\n \"description\": \"<string>\",\n \"parameters\": {}\n }\n }\n ],\n \"tool_choice\": \"<string>\",\n \"response_format\": {\n \"type\": \"<string>\"\n },\n \"seed\": 123,\n \"user\": \"<string>\",\n \"routing\": {\n \"strategy\": \"<string>\",\n \"fallback\": [\n \"<string>\"\n ],\n \"allow_upgrade\": true\n },\n \"cache\": {\n \"enabled\": true,\n \"ttl\": 123\n }\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.openmodex.com/v1/chat/completions")
.header("Authorization", "Bearer <token>")
.header("Content-Type", "application/json")
.body("{\n \"model\": \"<string>\",\n \"messages\": [\n {\n \"content\": \"<string>\",\n \"name\": \"<string>\",\n \"tool_call_id\": \"<string>\",\n \"tool_calls\": [\n {\n \"id\": \"<string>\",\n \"type\": \"function\",\n \"function\": {\n \"name\": \"<string>\",\n \"arguments\": \"<string>\"\n }\n }\n ]\n }\n ],\n \"stream\": false,\n \"temperature\": 1,\n \"top_p\": 123,\n \"n\": 123,\n \"max_tokens\": 123,\n \"stop\": \"<string>\",\n \"frequency_penalty\": 0,\n \"presence_penalty\": 0,\n \"logit_bias\": {},\n \"tools\": [\n {\n \"type\": \"function\",\n \"function\": {\n \"name\": \"<string>\",\n \"description\": \"<string>\",\n \"parameters\": {}\n }\n }\n ],\n \"tool_choice\": \"<string>\",\n \"response_format\": {\n \"type\": \"<string>\"\n },\n \"seed\": 123,\n \"user\": \"<string>\",\n \"routing\": {\n \"strategy\": \"<string>\",\n \"fallback\": [\n \"<string>\"\n ],\n \"allow_upgrade\": true\n },\n \"cache\": {\n \"enabled\": true,\n \"ttl\": 123\n }\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.openmodex.com/v1/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 \"model\": \"<string>\",\n \"messages\": [\n {\n \"content\": \"<string>\",\n \"name\": \"<string>\",\n \"tool_call_id\": \"<string>\",\n \"tool_calls\": [\n {\n \"id\": \"<string>\",\n \"type\": \"function\",\n \"function\": {\n \"name\": \"<string>\",\n \"arguments\": \"<string>\"\n }\n }\n ]\n }\n ],\n \"stream\": false,\n \"temperature\": 1,\n \"top_p\": 123,\n \"n\": 123,\n \"max_tokens\": 123,\n \"stop\": \"<string>\",\n \"frequency_penalty\": 0,\n \"presence_penalty\": 0,\n \"logit_bias\": {},\n \"tools\": [\n {\n \"type\": \"function\",\n \"function\": {\n \"name\": \"<string>\",\n \"description\": \"<string>\",\n \"parameters\": {}\n }\n }\n ],\n \"tool_choice\": \"<string>\",\n \"response_format\": {\n \"type\": \"<string>\"\n },\n \"seed\": 123,\n \"user\": \"<string>\",\n \"routing\": {\n \"strategy\": \"<string>\",\n \"fallback\": [\n \"<string>\"\n ],\n \"allow_upgrade\": true\n },\n \"cache\": {\n \"enabled\": true,\n \"ttl\": 123\n }\n}"
response = http.request(request)
puts response.read_body{
"id": "<string>",
"object": "chat.completion",
"created": 123,
"model": "<string>",
"choices": [
{
"index": 123,
"message": {
"role": "<string>",
"content": "<string>",
"tool_calls": [
{
"id": "<string>",
"type": "function",
"function": {
"name": "<string>",
"arguments": "<string>"
}
}
]
},
"finish_reason": "stop"
}
],
"usage": {
"prompt_tokens": 123,
"completion_tokens": 123,
"total_tokens": 123,
"cost_usd": 123
},
"system_fingerprint": "<string>",
"openmodex": {
"request_id": "<string>",
"model_used": "<string>",
"provider": "<string>",
"cache_hit": true,
"routing_strategy": "<string>",
"fallback_used": true,
"latency_ms": 123
}
}{
"error": {
"message": "<string>",
"type": "<string>",
"code": "<string>"
}
}{
"error": {
"message": "<string>",
"type": "<string>",
"code": "<string>"
}
}{
"error": {
"message": "<string>",
"type": "<string>",
"code": "<string>"
}
}{
"error": {
"message": "<string>",
"type": "<string>",
"code": "<string>"
}
}{
"error": {
"message": "<string>",
"type": "<string>",
"code": "<string>"
}
}{
"error": {
"message": "<string>",
"type": "<string>",
"code": "<string>"
}
}{
"error": {
"message": "<string>",
"type": "<string>",
"code": "<string>"
}
}{
"error": {
"message": "<string>",
"type": "<string>",
"code": "<string>"
}
}請求主體
gpt-4o、claude-3.5-sonnet、gemini-2.0-flash)。true,回傳 Server-Sent Events (SSE) 串流。auto、none 或指定的工具。{"type": "json_object"})。OpenModex 擴充功能
回應
{
"id": "chatcmpl-abc123",
"object": "chat.completion",
"created": 1700000000,
"model": "gpt-4o-2024-08-06",
"choices": [
{
"index": 0,
"message": {
"role": "assistant",
"content": "Hello! How can I help you today?"
},
"finish_reason": "stop"
}
],
"usage": {
"prompt_tokens": 10,
"completion_tokens": 9,
"total_tokens": 19,
"cost_usd": 0.000145
},
"openmodex": {
"request_id": "req_abc123",
"model_used": "gpt-4o-2024-08-06",
"provider": "openai",
"cache_hit": false,
"routing_strategy": "default",
"fallback_used": false,
"latency_ms": 850
}
}
範例
curl https://api.openmodex.com/v1/chat/completions \
-H "Authorization: Bearer omx_sk_YOUR_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "gpt-4o",
"messages": [
{"role": "system", "content": "You are a helpful assistant."},
{"role": "user", "content": "What is the capital of France?"}
],
"temperature": 0.7,
"max_tokens": 100
}'
import OpenModex from '@openmodex/sdk';
const client = new OpenModex({ apiKey: 'omx_sk_YOUR_KEY' });
const response = await client.chat.completions.create({
model: 'gpt-4o',
messages: [
{ role: 'system', content: 'You are a helpful assistant.' },
{ role: 'user', content: 'What is the capital of France?' },
],
temperature: 0.7,
max_tokens: 100,
});
console.log(response.choices[0].message.content);
from openmodex import OpenModex
client = OpenModex(api_key="omx_sk_YOUR_KEY")
response = client.chat.completions.create(
model="gpt-4o",
messages=[
{"role": "system", "content": "You are a helpful assistant."},
{"role": "user", "content": "What is the capital of France?"},
],
temperature=0.7,
max_tokens=100,
)
print(response.choices[0].message.content)
授權
API key authentication. Pass your OpenModex API key as a Bearer token in the Authorization header: Authorization: Bearer omx_sk_...
主體
Request body for creating a chat completion.
ID of the model to use.
A list of messages comprising the conversation so far.
Show child attributes
Show child attributes
If true, partial message deltas will be sent as server-sent events.
Sampling temperature between 0 and 2. Higher values make output more random.
0 <= x <= 2Nucleus sampling parameter. Only consider tokens with top_p probability mass.
How many completions to generate for each prompt.
The maximum number of tokens to generate in the completion.
Up to 4 sequences where the API will stop generating further tokens.
Penalizes new tokens based on their existing frequency in the text so far.
-2 <= x <= 2Penalizes new tokens based on whether they appear in the text so far.
-2 <= x <= 2Modify the likelihood of specified tokens appearing in the completion. Maps token IDs to bias values from -100 to 100.
Show child attributes
Show child attributes
A list of tools the model may call.
Show child attributes
Show child attributes
Controls which tool is called by the model. Can be 'none', 'auto', 'required', or a specific tool object.
An object specifying the format the model must output (e.g., {"type": "json_object"}).
Show child attributes
Show child attributes
If specified, the system will attempt to sample deterministically.
A unique identifier representing your end-user, for abuse monitoring.
Configuration for intelligent request routing.
Show child attributes
Show child attributes
Configuration for response caching.
Show child attributes
Show child attributes
回應
Chat completion response. When stream=true, returns SSE stream of ChatCompletionChunk objects.
Response from a chat completion request.
A unique identifier for the completion.
The object type, always 'chat.completion'.
chat.completion Unix timestamp (in seconds) of when the completion was created.
The model used for the completion.
A list of completion choices.
Show child attributes
Show child attributes
Token usage statistics for a completion request.
Show child attributes
Show child attributes
A fingerprint representing the backend configuration.
OpenModex-specific metadata included in completion responses.
Show child attributes
Show child attributes