OpenAI-compatible chat completion
curl --request POST \
--url https://secureai.hiperai.ai/api/external/v1/chat/completions \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '
{
"model": "openai/gpt-5-nano",
"messages": [
{
"content": "<string>"
}
],
"temperature": 123,
"max_tokens": 123,
"stream": true,
"models": [
"<string>"
],
"fallback_models": [
"<string>"
],
"redundancy": {},
"smltp_policy": "<string>",
"prompt_shield": {}
}
'import requests
url = "https://secureai.hiperai.ai/api/external/v1/chat/completions"
payload = {
"model": "openai/gpt-5-nano",
"messages": [{ "content": "<string>" }],
"temperature": 123,
"max_tokens": 123,
"stream": True,
"models": ["<string>"],
"fallback_models": ["<string>"],
"redundancy": {},
"smltp_policy": "<string>",
"prompt_shield": {}
}
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: 'openai/gpt-5-nano',
messages: [{content: '<string>'}],
temperature: 123,
max_tokens: 123,
stream: true,
models: ['<string>'],
fallback_models: ['<string>'],
redundancy: {},
smltp_policy: '<string>',
prompt_shield: {}
})
};
fetch('https://secureai.hiperai.ai/api/external/v1/chat/completions', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));模型与 AI 生成
OpenAI 兼容端点
直接 OpenAI 聊天完成界面 — 将任何 OpenAI SDK 指向 SecureAI
POST
/
v1
/
chat
/
completions
OpenAI-compatible chat completion
curl --request POST \
--url https://secureai.hiperai.ai/api/external/v1/chat/completions \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '
{
"model": "openai/gpt-5-nano",
"messages": [
{
"content": "<string>"
}
],
"temperature": 123,
"max_tokens": 123,
"stream": true,
"models": [
"<string>"
],
"fallback_models": [
"<string>"
],
"redundancy": {},
"smltp_policy": "<string>",
"prompt_shield": {}
}
'import requests
url = "https://secureai.hiperai.ai/api/external/v1/chat/completions"
payload = {
"model": "openai/gpt-5-nano",
"messages": [{ "content": "<string>" }],
"temperature": 123,
"max_tokens": 123,
"stream": True,
"models": ["<string>"],
"fallback_models": ["<string>"],
"redundancy": {},
"smltp_policy": "<string>",
"prompt_shield": {}
}
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: 'openai/gpt-5-nano',
messages: [{content: '<string>'}],
temperature: 123,
max_tokens: 123,
stream: true,
models: ['<string>'],
fallback_models: ['<string>'],
redundancy: {},
smltp_policy: '<string>',
prompt_shield: {}
})
};
fetch('https://secureai.hiperai.ai/api/external/v1/chat/completions', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));OpenAI 兼容端点
SecureAI 公开了与 OpenAI 兼容的表面,因此您可以通过仅更改基本 URL 和 API 密钥来与 **任何 OpenAI SDK 集成 - 无需更改代码。完整的 SecureAI 安全堆栈(API 密钥身份验证、模型/索引允许列表、SMLTP 策略执行 + 权利、Prompt Shield、PII/DLP、积分计费和模型冗余引擎)在下面运行。端点
POST /api/external/v1/chat/completions
GET /api/external/v1/models
base_url 指向:
https://{customer.name}.hiperai.ai/api/external/v1
仅零知识该表面不支持RAG/知识库。请求被固定到
Zero-Knowledge。如果您需要知识库检索,请使用经典的聊天完成端点。身份验证
Authorization: Bearer sk-your-api-key-here
使用 OpenAI SDK
Python (openai)
from openai import OpenAI
client = OpenAI(
api_key="sk-your-api-key-here",
base_url="https://{customer.name}.hiperai.ai/api/external/v1",
)
resp = client.chat.completions.create(
model="openai/gpt-5-nano",
messages=[{"role": "user", "content": "Hello!"}],
# SecureAI extensions travel via extra_body
extra_body={
"smltp_policy": "internal",
"fallback_models": ["anthropic/claude-sonnet-4"],
},
)
print(resp.choices[0].message.content)
print(resp.model_extra["secureai"]["served_model"])
JavaScript (openai)
import OpenAI from 'openai';
const client = new OpenAI({
apiKey: 'sk-your-api-key-here',
baseURL: 'https://{customer.name}.hiperai.ai/api/external/v1',
});
const resp = await client.chat.completions.create({
model: 'openai/gpt-5-nano',
messages: [{ role: 'user', content: 'Hello!' }],
// @ts-expect-error — SecureAI extension fields
smltp_policy: 'internal',
fallback_models: ['anthropic/claude-sonnet-4'],
});
console.log(resp.choices[0].message.content);
请求正文
支持标准 OpenAI 字段。messages 是必需的(该表面上没有 prompt)。 max_completion_tokens 被接受作为 max_tokens 的别名。
以下 OpenAI 参数按原样传递给提供商:
tools、tool_choice、parallel_tool_calls、response_format、stop、top_p、frequency_penalty、presence_penalty、seed、logprobs、top_logprobs、 user。
SecureAI 扩展字段
将它们作为额外的正文字段发送(通过 OpenAI SDK 中的extra_body):
| 领域 | 描述 |
|---|---|
smltp_policy | SMLTP 此调用的安全策略。 |
prompt_shield | { enabled?, policy? } — 每次呼叫提示屏蔽覆盖。 |
models / fallback_models | 模型冗余链。 |
redundancy | { timeout_ms, first_token_timeout_ms, on[] }。 |
user_id | 向不同的用户计费(管理员控制)。 |
回应
标准 OpenAIchat.completion 形状,加上 secureai 扩展对象。
{
"id": "chatcmpl-1a2b3c...",
"object": "chat.completion",
"created": 1705312200,
"model": "anthropic/claude-sonnet-4",
"choices": [
{ "index": 0, "message": { "role": "assistant", "content": "Hello!" }, "finish_reason": "stop" }
],
"usage": { "prompt_tokens": 9, "completion_tokens": 3, "total_tokens": 12 },
"secureai": {
"served_model": "anthropic/claude-sonnet-4",
"requested_model": "openai/gpt-5-nano",
"failover": { "occurred": true, "attempts": [ ... ] },
"smltp_policy_used": "internal",
"smltp_policy_source": "request",
"smltp_policy_hash": "a1b2c3...",
"prompt_shield_policy": null,
"smltp_bundle_id": "bnd_..."
}
}
secureai.smltp_bundle_id(如果存在)可以兑换为已签名的合规性收据。
流媒体
设置stream: true。帧是由 data: [DONE] 终止的本机 OpenAI chat.completion.chunk 对象。 secureai 扩展附加到 first 块。 choices(包括tool_calls增量和finish_reason)不受影响地通过。
错误
此处理程序中的错误使用 OpenAI 信封:{ "error": { "message": "you must provide a model parameter", "type": "invalid_request_error", "code": null } }
code: "all_models_failed" 和状态 429(所有速率限制)或 502(否则)。安全中间件拒绝保持 SecureAI { "success": false, ... } 的形状;两者都始终带有 message。
相关
授权
API key authentication using Bearer token format.
Example: Authorization: Bearer sk-your-api-key-here
请求体
application/json
示例:
"openai/gpt-5-nano"
Show child attributes
Show child attributes
{ timeout_ms, first_token_timeout_ms, on[] }
{ enabled?, policy? } per-call Prompt Shield override
响应
OpenAI chat.completion object plus a secureai extension

