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 Chat Completions サーフェス — 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 ポリシーの適用 + 資格、プロンプト シールド、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 に固定されます。ナレッジベースの取得が必要な場合は、従来の Chat Completion エンドポイントを使用してください。認証
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 拡張子は 最初 チャンクに付加されます。 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 を持ちます。
関連
- チャット補完 — クラシック サーフェス (RAG を追加)。
- 冗長性とフェイルオーバー
- プロンプト シールド API
承認
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

