Chat Completions
POST /v1/chat/completions· OpenAI 互換
1 回のチャット補完を作成します。これは Nexith のメインインターフェースです。OpenAI SDK、Codex、OpenCode などが
そのまま利用できます。標準フィールドに加えて、Nexith は少数の nexith_* 拡張フィールドを提供します。送信しなければ
標準の OpenAI 動作に完全に退化します。
リクエスト#
POST /v1/chat/completions
Authorization: Bearer nx-...
Content-Type: application/jsonBody#
| フィールド | 型 | 必須 | 説明 |
|---|---|---|---|
model |
string | ✅ | nexith-core(エイリアス nexith-8b) |
messages |
array | ✅ | 下表参照 |
stream |
bool | — | デフォルト false |
stream_options |
object | — | {"include_usage": true} でストリーム末尾に使用量フレームを追加 |
temperature |
number | — | 0–2 |
top_p |
number | — | 0–1 |
max_tokens |
integer | — | 本文 + 隠れた推論の合計予算(アップストリームが推論モデルの場合) |
frequency_penalty |
number | — | -2.0–2.0 |
presence_penalty |
number | — | -2.0–2.0 |
user |
string | — | そのまま透過。認証/課金には関与しません |
reasoning_effort |
string | — | none / low / medium / high |
tools |
array | — | OpenAI function のツール定義。そのまま転送 |
tool_choice |
string/object | — | auto / none / required / 関数指定 |
parallel_tool_calls |
bool | — | 1 ターンで複数のツール呼び出しを許可するか |
messages#
| role | content |
|---|---|
system |
文字列または parts |
user |
文字列または parts(parts には text、image_url を含められます) |
assistant |
文字列、または tool_calls 付き |
tool |
ツール結果。tool_call_id が必須 |
画像コンテンツブロック:
{
"role": "user",
"content": [
{"type": "text", "text": "这张图里有什么?"},
{"type": "image_url", "image_url": {"url": "https://…/cat.png"}}
]
}image_url.url は https URL、data:image/...;base64,...、および nx-file://<id> をサポートします。
Nexith 拡張フィールド#
| フィールド | 型 | 説明 |
|---|---|---|
nexith_capability |
string | ケイパビリティヒント:code / plan / audit / reason / text / translate。内部ディスパッチにのみ影響し、価格は変わりません |
inject_memory |
bool | 該当ユーザー/アプリの長期記憶を検索し、system コンテキストに注入 |
return_memory |
bool | ヒットした記憶候補をレスポンスの nexith.memory に返す(非ストリーミングのみ) |
remember |
bool | 回答後に事実を非同期で抽出し、長期記憶へ書き込み(非ストリーミングのみ) |
nexith_detect_media |
bool | 同じ L1 分類で画像生成意図を識別し、ヒット時は nexith.image_request を返す |
nexith_web_search |
bool | L1 がリアルタイム情報を必要と判断した場合、自動で Web 検索して注入 |
nexith_deep_research |
bool | 単一ターンの agentic 深掘り調査(計画→検索→本文取得→圧縮→統合) |
nexith_coordination |
bool | クライアント管理のツールループ向けに計画/レビューのコンテキストを有効化(ゲートウェイはツールを実行しません) |
これらのフィールドはアップストリームへ転送されず、
GET /v1/modelsの互換性保証にも含まれません。 送信しない場合の動作は標準 OpenAI と完全に同一です。
レスポンス(非ストリーミング)#
{
"id": "chatcmpl-8f2a…",
"object": "chat.completion",
"created": 1795055220,
"model": "nexith-core",
"choices": [
{
"index": 0,
"message": {"role": "assistant", "content": "…"},
"finish_reason": "stop"
}
],
"usage": {
"prompt_tokens": 320,
"completion_tokens": 2,
"total_tokens": 322,
"prompt_tokens_details": {"cached_tokens": 128},
"completion_tokens_details": {"reasoning_tokens": 0}
},
"nexith": {
"sources": [{"title": "…", "url": "…", "content": "…"}],
"memory": [{"id": "…", "content": "…", "score": 0.83}],
"steps": [{"label": "…", "model": "…", "content": "…"}]
}
}nexithはオプションのオブジェクトで、対応する拡張が有効かつヒットした場合にのみ現れます。- ツール呼び出しは
message.tool_callsを返し、形式は OpenAI と同一です。
レスポンス(ストリーミング)#
stream=true の場合は text/event-stream を返します。フレーム形式と終了マーカーは
ストリーミングプロトコルを参照してください。
例#
基本#
curl https://api.nexith.ai/v1/chat/completions \
-H "Authorization: Bearer $NEXITH_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "nexith-core",
"messages": [{"role": "user", "content": "你好"}]
}'ツール呼び出し#
{
"model": "nexith-core",
"messages": [{"role": "user", "content": "北京现在天气怎么样?"}],
"tools": [{
"type": "function",
"function": {
"name": "get_weather",
"description": "查询城市天气",
"parameters": {
"type": "object",
"properties": {"city": {"type": "string"}},
"required": ["city"]
}
}
}],
"tool_choice": "auto"
}ストリーミング + 使用量#
{
"model": "nexith-core",
"messages": [{"role": "user", "content": "写一段 100 字的介绍"}],
"stream": true,
"stream_options": {"include_usage": true}
}動作について#
- 自動エスカレーション:困難なタスクは内部的に高性能なアップストリームへエスカレーションして実行される場合がありますが、
モデル ID、課金、アイデンティティガードレールは常に
nexith-coreに従い、呼び出し元は意識する必要がありません。 - セマンティックキャッシュ:等価な単一ターンの質問はキャッシュにヒットする場合があります。ヒット時はキャッシュ入力価格で 課金され、レスポンス本体は通常の回答と同じです。
- コンテキスト:1,048,576 tokens を超える入力はトリミングされます(system、最初の user、直近の内容を保持)。 エラーにはなりません。
- エラー:エラーとレート制限を参照してください。