curl --request POST \
--url https://api.openmodex.com/v1/completions \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '
{
"model": "<string>",
"prompt": "<string>",
"max_tokens": 123,
"temperature": 123,
"top_p": 123,
"n": 123,
"stream": false,
"stop": "<string>",
"frequency_penalty": 123,
"presence_penalty": 123,
"logit_bias": {},
"suffix": "<string>",
"user": "<string>",
"routing": {
"strategy": "<string>",
"fallback": [
"<string>"
],
"allow_upgrade": true
}
}
'import requests
url = "https://api.openmodex.com/v1/completions"
payload = {
"model": "<string>",
"prompt": "<string>",
"max_tokens": 123,
"temperature": 123,
"top_p": 123,
"n": 123,
"stream": False,
"stop": "<string>",
"frequency_penalty": 123,
"presence_penalty": 123,
"logit_bias": {},
"suffix": "<string>",
"user": "<string>",
"routing": {
"strategy": "<string>",
"fallback": ["<string>"],
"allow_upgrade": True
}
}
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>',
prompt: '<string>',
max_tokens: 123,
temperature: 123,
top_p: 123,
n: 123,
stream: false,
stop: '<string>',
frequency_penalty: 123,
presence_penalty: 123,
logit_bias: {},
suffix: '<string>',
user: '<string>',
routing: {strategy: '<string>', fallback: ['<string>'], allow_upgrade: true}
})
};
fetch('https://api.openmodex.com/v1/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/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>',
'prompt' => '<string>',
'max_tokens' => 123,
'temperature' => 123,
'top_p' => 123,
'n' => 123,
'stream' => false,
'stop' => '<string>',
'frequency_penalty' => 123,
'presence_penalty' => 123,
'logit_bias' => [
],
'suffix' => '<string>',
'user' => '<string>',
'routing' => [
'strategy' => '<string>',
'fallback' => [
'<string>'
],
'allow_upgrade' => true
]
]),
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/completions"
payload := strings.NewReader("{\n \"model\": \"<string>\",\n \"prompt\": \"<string>\",\n \"max_tokens\": 123,\n \"temperature\": 123,\n \"top_p\": 123,\n \"n\": 123,\n \"stream\": false,\n \"stop\": \"<string>\",\n \"frequency_penalty\": 123,\n \"presence_penalty\": 123,\n \"logit_bias\": {},\n \"suffix\": \"<string>\",\n \"user\": \"<string>\",\n \"routing\": {\n \"strategy\": \"<string>\",\n \"fallback\": [\n \"<string>\"\n ],\n \"allow_upgrade\": true\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/completions")
.header("Authorization", "Bearer <token>")
.header("Content-Type", "application/json")
.body("{\n \"model\": \"<string>\",\n \"prompt\": \"<string>\",\n \"max_tokens\": 123,\n \"temperature\": 123,\n \"top_p\": 123,\n \"n\": 123,\n \"stream\": false,\n \"stop\": \"<string>\",\n \"frequency_penalty\": 123,\n \"presence_penalty\": 123,\n \"logit_bias\": {},\n \"suffix\": \"<string>\",\n \"user\": \"<string>\",\n \"routing\": {\n \"strategy\": \"<string>\",\n \"fallback\": [\n \"<string>\"\n ],\n \"allow_upgrade\": true\n }\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.openmodex.com/v1/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 \"prompt\": \"<string>\",\n \"max_tokens\": 123,\n \"temperature\": 123,\n \"top_p\": 123,\n \"n\": 123,\n \"stream\": false,\n \"stop\": \"<string>\",\n \"frequency_penalty\": 123,\n \"presence_penalty\": 123,\n \"logit_bias\": {},\n \"suffix\": \"<string>\",\n \"user\": \"<string>\",\n \"routing\": {\n \"strategy\": \"<string>\",\n \"fallback\": [\n \"<string>\"\n ],\n \"allow_upgrade\": true\n }\n}"
response = http.request(request)
puts response.read_body{
"id": "<string>",
"object": "text_completion",
"created": 123,
"model": "<string>",
"choices": [
{
"index": 123,
"text": "<string>",
"finish_reason": "stop"
}
],
"usage": {
"prompt_tokens": 123,
"completion_tokens": 123,
"total_tokens": 123,
"cost_usd": 123
},
"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/completions — 创建文本补全(旧版)。
curl --request POST \
--url https://api.openmodex.com/v1/completions \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '
{
"model": "<string>",
"prompt": "<string>",
"max_tokens": 123,
"temperature": 123,
"top_p": 123,
"n": 123,
"stream": false,
"stop": "<string>",
"frequency_penalty": 123,
"presence_penalty": 123,
"logit_bias": {},
"suffix": "<string>",
"user": "<string>",
"routing": {
"strategy": "<string>",
"fallback": [
"<string>"
],
"allow_upgrade": true
}
}
'import requests
url = "https://api.openmodex.com/v1/completions"
payload = {
"model": "<string>",
"prompt": "<string>",
"max_tokens": 123,
"temperature": 123,
"top_p": 123,
"n": 123,
"stream": False,
"stop": "<string>",
"frequency_penalty": 123,
"presence_penalty": 123,
"logit_bias": {},
"suffix": "<string>",
"user": "<string>",
"routing": {
"strategy": "<string>",
"fallback": ["<string>"],
"allow_upgrade": True
}
}
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>',
prompt: '<string>',
max_tokens: 123,
temperature: 123,
top_p: 123,
n: 123,
stream: false,
stop: '<string>',
frequency_penalty: 123,
presence_penalty: 123,
logit_bias: {},
suffix: '<string>',
user: '<string>',
routing: {strategy: '<string>', fallback: ['<string>'], allow_upgrade: true}
})
};
fetch('https://api.openmodex.com/v1/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/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>',
'prompt' => '<string>',
'max_tokens' => 123,
'temperature' => 123,
'top_p' => 123,
'n' => 123,
'stream' => false,
'stop' => '<string>',
'frequency_penalty' => 123,
'presence_penalty' => 123,
'logit_bias' => [
],
'suffix' => '<string>',
'user' => '<string>',
'routing' => [
'strategy' => '<string>',
'fallback' => [
'<string>'
],
'allow_upgrade' => true
]
]),
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/completions"
payload := strings.NewReader("{\n \"model\": \"<string>\",\n \"prompt\": \"<string>\",\n \"max_tokens\": 123,\n \"temperature\": 123,\n \"top_p\": 123,\n \"n\": 123,\n \"stream\": false,\n \"stop\": \"<string>\",\n \"frequency_penalty\": 123,\n \"presence_penalty\": 123,\n \"logit_bias\": {},\n \"suffix\": \"<string>\",\n \"user\": \"<string>\",\n \"routing\": {\n \"strategy\": \"<string>\",\n \"fallback\": [\n \"<string>\"\n ],\n \"allow_upgrade\": true\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/completions")
.header("Authorization", "Bearer <token>")
.header("Content-Type", "application/json")
.body("{\n \"model\": \"<string>\",\n \"prompt\": \"<string>\",\n \"max_tokens\": 123,\n \"temperature\": 123,\n \"top_p\": 123,\n \"n\": 123,\n \"stream\": false,\n \"stop\": \"<string>\",\n \"frequency_penalty\": 123,\n \"presence_penalty\": 123,\n \"logit_bias\": {},\n \"suffix\": \"<string>\",\n \"user\": \"<string>\",\n \"routing\": {\n \"strategy\": \"<string>\",\n \"fallback\": [\n \"<string>\"\n ],\n \"allow_upgrade\": true\n }\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.openmodex.com/v1/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 \"prompt\": \"<string>\",\n \"max_tokens\": 123,\n \"temperature\": 123,\n \"top_p\": 123,\n \"n\": 123,\n \"stream\": false,\n \"stop\": \"<string>\",\n \"frequency_penalty\": 123,\n \"presence_penalty\": 123,\n \"logit_bias\": {},\n \"suffix\": \"<string>\",\n \"user\": \"<string>\",\n \"routing\": {\n \"strategy\": \"<string>\",\n \"fallback\": [\n \"<string>\"\n ],\n \"allow_upgrade\": true\n }\n}"
response = http.request(request)
puts response.read_body{
"id": "<string>",
"object": "text_completion",
"created": 123,
"model": "<string>",
"choices": [
{
"index": 123,
"text": "<string>",
"finish_reason": "stop"
}
],
"usage": {
"prompt_tokens": 123,
"completion_tokens": 123,
"total_tokens": 123,
"cost_usd": 123
},
"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>"
}
}请求体
响应
{
"id": "cmpl-abc123",
"object": "text_completion",
"created": 1700000000,
"model": "gpt-3.5-turbo-instruct",
"choices": [
{
"index": 0,
"text": " a time, in a land far away...",
"finish_reason": "length"
}
],
"usage": {
"prompt_tokens": 5,
"completion_tokens": 10,
"total_tokens": 15
}
}
示例
curl https://api.openmodex.com/v1/completions \
-H "Authorization: Bearer omx_sk_YOUR_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "gpt-3.5-turbo-instruct",
"prompt": "Once upon",
"max_tokens": 100
}'
授权
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 text completion (legacy).
ID of the model to use.
The prompt(s) to generate completions for.
The maximum number of tokens to generate.
Sampling temperature between 0 and 2.
Nucleus sampling parameter.
How many completions to generate for each prompt.
Whether to stream back partial progress via SSE.
Up to 4 sequences where the API will stop generating further tokens.
Penalizes new tokens based on their existing frequency in the text.
Penalizes new tokens based on whether they appear in the text so far.
Modify the likelihood of specified tokens appearing in the completion.
Show child attributes
Show child attributes
The suffix that comes after a completion of inserted text.
A unique identifier representing your end-user.
Configuration for intelligent request routing.
Show child attributes
Show child attributes
响应
Text completion response.
Response from a text completion request.
A unique identifier for the completion.
The object type, always 'text_completion'.
text_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
OpenModex-specific metadata included in completion responses.
Show child attributes
Show child attributes