メインコンテンツへスキップ
POST
/
v1
/
chat
/
completions
チャット補完を作成
curl --request POST \
  --url https://api.example.com/v1/chat/completions/ \
  --header 'Authorization: Bearer <token>' \
  --header 'Content-Type: application/json' \
  --data '
{
  "messages": [
    {
      "content": "<string>",
      "role": "<string>",
      "name": "<string>"
    }
  ],
  "model": "<string>",
  "frequency_penalty": 0,
  "logit_bias": {},
  "logprobs": false,
  "top_logprobs": 0,
  "max_tokens": 123,
  "max_completion_tokens": 123,
  "n": 1,
  "presence_penalty": 0,
  "response_format": {
    "type": "text",
    "json_schema": {
      "name": "<string>",
      "description": "<string>",
      "schema": {},
      "strict": true
    }
  },
  "seed": 0,
  "stop": [],
  "stream": false,
  "stream_options": {
    "include_usage": true,
    "continuous_usage_stats": false
  },
  "temperature": 123,
  "top_p": 123,
  "tools": [
    {
      "function": {
        "name": "<string>",
        "description": "<string>",
        "parameters": {}
      },
      "type": "function"
    }
  ],
  "tool_choice": "none",
  "reasoning_effort": "low",
  "include_reasoning": true,
  "parallel_tool_calls": true,
  "user": "<string>",
  "use_beam_search": false,
  "top_k": 123,
  "min_p": 123,
  "repetition_penalty": 123,
  "length_penalty": 1,
  "stop_token_ids": [],
  "include_stop_str_in_output": false,
  "ignore_eos": false,
  "min_tokens": 0,
  "skip_special_tokens": true,
  "spaces_between_special_tokens": true,
  "truncate_prompt_tokens": 0,
  "prompt_logprobs": 123,
  "allowed_token_ids": [
    123
  ],
  "bad_words": [
    "<string>"
  ],
  "echo": false,
  "add_generation_prompt": true,
  "continue_final_message": false,
  "add_special_tokens": false,
  "documents": [
    {}
  ],
  "chat_template": "<string>",
  "chat_template_kwargs": {},
  "mm_processor_kwargs": {},
  "structured_outputs": {
    "json": "<string>",
    "regex": "<string>",
    "choice": [
      "<string>"
    ],
    "grammar": "<string>",
    "json_object": true,
    "disable_fallback": false,
    "disable_any_whitespace": false,
    "disable_additional_properties": false,
    "whitespace_pattern": "<string>",
    "structural_tag": "<string>",
    "_backend": "<string>",
    "_backend_was_auto": false
  },
  "priority": 0,
  "request_id": "<string>",
  "logits_processors": [
    "<string>"
  ],
  "return_tokens_as_token_ids": true,
  "return_token_ids": true,
  "cache_salt": "<string>",
  "kv_transfer_params": {},
  "vllm_xargs": {}
}
'
{
  "model": "<string>",
  "choices": [
    {
      "index": 123,
      "message": {
        "role": "<string>",
        "content": "<string>",
        "refusal": "<string>",
        "annotations": {
          "type": "<string>",
          "url_citation": {
            "end_index": 123,
            "start_index": 123,
            "title": "<string>",
            "url": "<string>"
          }
        },
        "audio": {
          "id": "<string>",
          "data": "<string>",
          "expires_at": 123,
          "transcript": "<string>"
        },
        "function_call": {
          "name": "<string>",
          "arguments": "<string>"
        },
        "tool_calls": [
          {
            "function": {
              "name": "<string>",
              "arguments": "<string>"
            },
            "id": "<string>",
            "type": "function"
          }
        ],
        "reasoning": "<string>",
        "reasoning_content": "<string>"
      },
      "logprobs": {
        "content": [
          {
            "token": "<string>",
            "logprob": -9999,
            "bytes": [
              123
            ],
            "top_logprobs": [
              {
                "token": "<string>",
                "logprob": -9999,
                "bytes": [
                  123
                ]
              }
            ]
          }
        ]
      },
      "finish_reason": "stop",
      "stop_reason": 123,
      "token_ids": [
        123
      ]
    }
  ],
  "usage": {
    "prompt_tokens": 0,
    "total_tokens": 0,
    "completion_tokens": 0,
    "prompt_tokens_details": {
      "cached_tokens": 123
    }
  },
  "id": "<string>",
  "object": "chat.completion",
  "created": 123,
  "service_tier": "auto",
  "system_fingerprint": "<string>",
  "prompt_logprobs": [
    {}
  ],
  "prompt_token_ids": [
    123
  ],
  "kv_transfer_params": {}
}

承認

Authorization
string
header
必須

Bearer authentication header of the form Bearer <token>, where <token> is your auth token.

ボディ

application/json
messages
(ChatCompletionDeveloperMessageParam · object | ChatCompletionSystemMessageParam · object | ChatCompletionUserMessageParam · object | ChatCompletionAssistantMessageParam · object | ChatCompletionToolMessageParam · object | ChatCompletionFunctionMessageParam · object | CustomChatCompletionMessageParam · object | Message · object)[]
必須

ユーザーから送信されるメッセージに関係なく、モデルが従うべき開発者提供の指示です。o1 モデル以降では、developer メッセージが従来の system メッセージに置き換わります。

model
string | null
frequency_penalty
number | null
デフォルト:0
logit_bias
Logit Bias · object
logprobs
boolean | null
デフォルト:false
top_logprobs
integer | null
デフォルト:0
max_tokens
integer | null
非推奨
max_completion_tokens
integer | null
n
integer | null
デフォルト:1
presence_penalty
number | null
デフォルト:0
response_format
ResponseFormat · object
seed
integer | null
必須範囲: -9223372036854776000 <= x <= 9223372036854776000
stop
デフォルト:[]
stream
boolean | null
デフォルト:false
stream_options
StreamOptions · object
temperature
number | null
top_p
number | null
tools
ChatCompletionToolsParam · object[] | null
tool_choice
デフォルト:none
Allowed value: "none"
reasoning_effort
enum<string> | null
利用可能なオプション:
low,
medium,
high
include_reasoning
boolean
デフォルト:true
parallel_tool_calls
boolean | null
デフォルト:true
user
string | null
top_k
integer | null
min_p
number | null
repetition_penalty
number | null
length_penalty
number
デフォルト:1
stop_token_ids
integer[] | null
include_stop_str_in_output
boolean
デフォルト:false
ignore_eos
boolean
デフォルト:false
min_tokens
integer
デフォルト:0
skip_special_tokens
boolean
デフォルト:true
spaces_between_special_tokens
boolean
デフォルト:true
truncate_prompt_tokens
integer | null
必須範囲: x >= -1
prompt_logprobs
integer | null
allowed_token_ids
integer[] | null
bad_words
string[]
echo
boolean
デフォルト:false

true の場合、新しいメッセージが同じロールに属していれば、その直前のメッセージに追記されます。

add_generation_prompt
boolean
デフォルト:true

true の場合、生成用プロンプトがチャットテンプレートに追加されます。これは、モデルの tokenizer 設定におけるチャットテンプレートで使用されるパラメータです。

continue_final_message
boolean
デフォルト:false

これが true に設定されている場合、チャットは、チャット内の最後のメッセージが EOS トークンなしの未完結な形になるようにフォーマットされます。モデルは新しいメッセージを開始するのではなく、このメッセージの続きを生成します。これにより、モデルの応答の一部を「事前入力(prefill)」することができます。add_generation_prompt と同時には使用できません。

add_special_tokens
boolean
デフォルト:false

true の場合、(BOS などの)特別トークンが、チャットテンプレートによって追加される内容に加えてプロンプトに追加されます。ほとんどのモデルでは特別トークンの追加はチャットテンプレート側で処理されるため、この値はデフォルトどおり false のままにしておく必要があります。

documents
Documents · object[] | null

RAG(retrieval-augmented generation)実行時に、モデルからアクセス可能になるドキュメントを表す dict のリストです。テンプレートが RAG をサポートしていない場合、この引数は無視されます。各ドキュメントは "title" と "text" のキーを含む dict にすることを推奨します。

chat_template
string | null

この変換で使用する Jinja テンプレートです。transformers v4.44 以降ではデフォルトのチャットテンプレートは使用できないため、tokenizer がチャットテンプレートを定義していない場合は、必ずチャットテンプレートを指定する必要があります。

chat_template_kwargs
Chat Template Kwargs · object

テンプレートレンダラーに渡す追加のキーワード引数(kwargs)です。チャットテンプレートから参照できます。

mm_processor_kwargs
Mm Processor Kwargs · object

HF プロセッサーに渡す追加のキーワード引数(kwargs)です。

structured_outputs
StructuredOutputsParams · object

構造化出力用の追加のキーワード引数(kwargs)です。

priority
integer
デフォルト:0

リクエストの優先度です(値が小さいほど早く処理されます。デフォルト: 0)。使用しているモデルが優先度スケジューリングをサポートしていない場合、0 以外の優先度を指定するとエラーが発生します。

request_id
string

このリクエストに関連付けられた request_id です。呼び出し元で明示的に指定しない場合は、ランダムな UUID(random_uuid)が自動生成されます。この ID は推論処理全体を通して使用され、レスポンスでも返されます。

logits_processors
(string | LogitsProcessorConstructor · object)[] | null

サンプリング時に適用する logits processor を指定するリストです。各要素は、logits processor の修飾名(qualified name)か、コンストラクタオブジェクトのいずれかです。コンストラクタは JSON オブジェクトで、必須フィールドとして processor クラス/ファクトリの修飾名を指定する 'qualname'、任意フィールドとして位置引数を含む 'args' とキーワード引数を含む 'kwargs' を持ちます。例:{'qualname': 'my_module.MyLogitsProcessor', 'args': [1, 2], 'kwargs': {'param': 'value'}}。

return_tokens_as_token_ids
boolean | null

'logprobs' と併せて指定された場合、トークンは 'token_id:{token_id}' という形式の文字列として表現されます。これにより、JSON でエンコードできないトークンを識別できるようになります。

return_token_ids
boolean | null

指定すると、生成されたテキストに加えてトークン ID もレスポンスに含まれます。ストリーミングモードでは、prompt_token_ids は最初のチャンクにのみ含まれ、token_ids には各チャンクごとの差分トークンが含まれます。これはデバッグ時や、生成テキストを入力トークンに対応付ける必要がある場合に有用です。

cache_salt
string | null

指定すると、マルチユーザー環境で攻撃者にプロンプトを推測されることを防ぐため、指定した文字列を用いて prefix キャッシュにソルトを追加します。ソルトはランダムで、第三者からアクセスされないよう保護されており、予測不能な十分な長さ(例: 256 ビットに相当する 43 文字の base64 エンコード文字列)である必要があります。

kv_transfer_params
Kv Transfer Params · object

分離型サービングで使用される KVTransfer パラメーターです。

vllm_xargs
Vllm Xargs · object

カスタム拡張機能で使用される、文字列または数値(あるいはそのリスト)からなる追加のリクエストパラメーターです。

レスポンス

成功時のレスポンス

model
string
必須
choices
ChatCompletionResponseChoice · object[]
必須
usage
UsageInfo · object
必須
id
string
object
string
デフォルト:chat.completion
Allowed value: "chat.completion"
created
integer
service_tier
enum<string> | null
利用可能なオプション:
auto,
default,
flex,
scale,
priority
system_fingerprint
string | null
prompt_logprobs
(object | null)[] | null
prompt_token_ids
integer[] | null
kv_transfer_params
Kv Transfer Params · object

KVTransfer パラメーターです。