> ## Documentation Index
> Fetch the complete documentation index at: https://docs.apigo.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# /v1/chat/completions

> 다중 대화, 도구 호출 및 스트리밍 응답을 위한 OpenAI 호환 채팅 완료 엔드포인트입니다.

チャット会話のモデル応答を作成します。

既存の OpenAI SDK、チャット クライアント、または従来のチャット完了ワークフローとの互換性が必要な場合、このエンドポイントが依然として最も安全なデフォルトです。サポートされるフィールドは、特に推論、ツールの使用、マルチモーダル入力など、モデルによって異なります。

## 統合ガイダンス

* `Authorization: Bearer {API_KEY}`で認証する
* これを既存の OpenAI スタイルのチャット統合のデフォルトのエントリ ポイントとして使用します
* 構造化された出力、マルチモーダル入力、およびツールのためのより統合されたインターフェイスが必要な場合は、`/v1/responses` をお勧めします。
* ストリーミング クライアントは、最後の JSON 応答を待つのではなく、SSE チャンクを段階的に処理する必要があります。

## リクエストのハイライト

* `messages` が必要であり、会話履歴を保持します
* `model` は必須であり、ターゲットモデルを選択します
* `temperature` と `top_p` は両方ともサンプリングに影響しますが、ほとんどの統合ではどちらか 1 つだけを調整する必要があります。
* トークンレベルの確率が必要な場合は、`logprobs` と `top_logprobs` を組み合わせます。
* キャッシュと安全性の帰属については、`prompt_cache_key` および `safety_identifier` を推奨します。

## 回答のハイライト

* 通常、プレーンテキストは `choices[0].message.content` から読み取られます。
* ツール呼び出しは `message.tool_calls` から読み取ることができます
* ストリーミング応答は SSE チャンクとして到着するため、段階的にマージする必要があります
* 使用状況のアカウンティングは、より詳細なトークンの内訳を含め、`usage` を通じて公開されます。


## OpenAPI

````yaml POST /v1/chat/completions
openapi: 3.1.0
info:
  title: OpenAPI Plant Store
  description: >-
    A sample API that uses a plant store as an example to demonstrate features
    in the OpenAPI specification
  license:
    name: MIT
  version: 1.0.0
servers:
  - url: https://maas.apigo.ai
security:
  - bearerAuth: []
paths:
  /v1/chat/completions:
    post:
      summary: OpenAI chat completions
      description: >-
        OpenAI-compatible chat completion endpoint for multi-turn conversations,
        tool calling, and streaming responses.
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/OpenAIChatCompletionsRequest'
      responses:
        '200':
          description: Successful chat completion response
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/OpenAIChatCompletionsResponse'
        '400':
          description: Invalid request
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
components:
  schemas:
    OpenAIChatCompletionsRequest:
      type: object
      required:
        - model
        - messages
      properties:
        model:
          type: string
          example: gpt-4o
        messages:
          type: array
          items:
            $ref: '#/components/schemas/OpenAIMessage'
        temperature:
          type: number
          format: double
          minimum: 0
          maximum: 2
          description: 采样温度。类型：double。取值范围：0-2。
        stream:
          type: boolean
    OpenAIChatCompletionsResponse:
      type: object
      properties:
        id:
          type: string
        object:
          type: string
          example: chat.completion
        choices:
          type: array
          items:
            type: object
            properties:
              index:
                type: integer
              message:
                $ref: '#/components/schemas/OpenAIMessage'
              finish_reason:
                type: string
        usage:
          type: object
          properties:
            prompt_tokens:
              type: integer
            completion_tokens:
              type: integer
            total_tokens:
              type: integer
    Error:
      required:
        - error
        - message
      type: object
      properties:
        error:
          type: integer
          format: int32
        message:
          type: string
    OpenAIMessage:
      type: object
      required:
        - role
        - content
      properties:
        role:
          type: string
          enum:
            - system
            - user
            - assistant
            - tool
        content:
          type: string
  securitySchemes:
    bearerAuth:
      type: http
      scheme: bearer

````