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

# Chat Completions

> <ul><li>대화 기록을 기반으로 모델 응답을 생성합니다. 스트리밍 및 비스트리밍 응답을 지원합니다.</li><li>OpenAI Chat Completions API와 호환됩니다.</li></ul>

<RequestExample>
  ```bash cURL theme={null} theme={null}
  curl --request POST \
    --url 'https://api.elkapi.com/v1/chat/completions' \
    --header 'Authorization: Bearer <token>' \
    --header 'Content-Type: application/json' \
    --data '{
    "model": "gpt-5.5",
    "messages": [
      {
        "role": "user",
        "content": "안녕하세요, 자기소개를 해 주세요"
      }
    ],
    "temperature": 1,
    "stream": false,
    "max_tokens": 1024,
    "response_format": "json"
  }'
  ```

  ```python Python theme={null} theme={null}
  import requests

  url = "https://api.elkapi.com/v1/chat/completions"
  headers = {
      "Authorization": "Bearer <token>"
  }
  headers["Content-Type"] = "application/json"
  payload = {
      "model": "gpt-5.5",
      "messages": [
          {
              "role": "user",
              "content": "안녕하세요, 자기소개를 해 주세요"
          }
      ],
      "temperature": 1,
      "stream": False,
      "max_tokens": 1024,
      "response_format": "json"
  }

  response = requests.request("POST", url, headers=headers, json=payload)
  print(response.json())
  ```

  ```javascript JavaScript theme={null} theme={null}
  const url = "https://api.elkapi.com/v1/chat/completions";

  const headers = {
    "Authorization": "Bearer <token>"
  };
  headers["Content-Type"] = "application/json";
  const payload = {
    "model": "gpt-5.5",
    "messages": [
      {
        "role": "user",
        "content": "안녕하세요, 자기소개를 해 주세요"
      }
    ],
    "temperature": 1,
    "stream": false,
    "max_tokens": 1024,
    "response_format": "json"
  };

  const response = await fetch(url, {
    method: "POST",
    headers,
    body: JSON.stringify(payload)
  });

  console.log(await response.json());
  ```
</RequestExample>

<ResponseExample>
  ```json 200 theme={null} theme={null}
  {
    "id": "id",
    "object": "chat.completion",
    "created": 1,
    "model": "gpt-5.5",
    "choices": [
      {
        "index": 1,
        "message": {
          "role": "user",
          "content": "안녕하세요, 자기소개를 해 주세요",
          "name": "name",
          "tool_calls": [
            {
              "id": {},
              "type": {},
              "function": {}
            }
          ],
          "tool_call_id": "tool_call_id",
          "reasoning_content": "reasoning_content"
        },
        "finish_reason": "stop"
      }
    ],
    "usage": {
      "prompt_tokens": 1,
      "completion_tokens": 1,
      "total_tokens": 1,
      "prompt_tokens_details": {
        "cached_tokens": 1,
        "text_tokens": 1,
        "audio_tokens": 1,
        "image_tokens": 1
      },
      "completion_tokens_details": {
        "text_tokens": 1,
        "audio_tokens": 1,
        "reasoning_tokens": 1
      }
    },
    "system_fingerprint": "system_fingerprint"
  }
  ```

  ```json 400 theme={null} theme={null}
  {
    "error": {
      "message": "message",
      "type": "type",
      "param": "param",
      "code": "code"
    }
  }
  ```

  ```json 429 theme={null} theme={null}
  {
    "error": {
      "message": "message",
      "type": "type",
      "param": "param",
      "code": "code"
    }
  }
  ```
</ResponseExample>

## Authorizations

<ParamField header="Authorization" type="string" required>
  모든 엔드포인트는 Bearer Token 인증이 필요합니다.

  요청 헤더에 추가하세요:

  ```
  Authorization: Bearer YOUR_API_KEY
  ```
</ParamField>

## Body

<ParamField body="model" type="string" required default="gpt-5.5">
  모델 ID

  예시: `gpt-5.5`
</ParamField>

<ParamField body="messages" type="array<object>" required>
  채팅 메시지 목록

  <ParamField body="messages.role" type="string" required>
    메시지 역할

    허용 값: `system`, `user`, `assistant`, `tool`, `developer`
  </ParamField>

  <ParamField body="messages.content" type="string or array<object>" required>
    메시지 내용
  </ParamField>

  <ParamField body="messages.name" type="string">
    발신자 이름
  </ParamField>

  <ParamField body="messages.tool_calls" type="array<object>">
    <ParamField body="messages.tool_calls.id" type="string" />

    <ParamField body="messages.tool_calls.type" type="string">
      예시: `function`
    </ParamField>

    <ParamField body="messages.tool_calls.function" type="object">
      <ParamField body="messages.tool_calls.function.name" type="string" />

      <ParamField body="messages.tool_calls.function.arguments" type="string" />
    </ParamField>
  </ParamField>

  <ParamField body="messages.tool_call_id" type="string">
    도구 호출 ID(tool 역할 메시지용)
  </ParamField>

  <ParamField body="messages.reasoning_content" type="string">
    추론 내용
  </ParamField>
</ParamField>

<ParamField body="temperature" type="number" default="1">
  샘플링 온도
</ParamField>

<ParamField body="top_p" type="number" default="1">
  뉴클리어스 샘플링 파라미터
</ParamField>

<ParamField body="n" type="integer" default="1">
  생성 수
</ParamField>

<ParamField body="stream" type="boolean" default="false">
  스트리밍 응답 여부
</ParamField>

<ParamField body="stream_options" type="object">
  <ParamField body="stream_options.include_usage" type="boolean" />
</ParamField>

<ParamField body="stop" type="string or array<string>">
  중지 시퀀스
</ParamField>

<ParamField body="max_tokens" type="integer">
  최대 생성 토큰 수
</ParamField>

<ParamField body="max_completion_tokens" type="integer">
  최대 완성 토큰 수
</ParamField>

<ParamField body="presence_penalty" type="number" default="0" />

<ParamField body="frequency_penalty" type="number" default="0" />

<ParamField body="logit_bias" type="object" />

<ParamField body="user" type="string" />

<ParamField body="tools" type="array<object>">
  <ParamField body="tools.type" type="string">
    예시: `function`
  </ParamField>

  <ParamField body="tools.function" type="object">
    <ParamField body="tools.function.name" type="string" />

    <ParamField body="tools.function.description" type="string" />

    <ParamField body="tools.function.parameters" type="object">
      JSON Schema 형식의 파라미터 정의
    </ParamField>
  </ParamField>
</ParamField>

<ParamField body="tool_choice" type="string or object">
  <ParamField body="tool_choice.type" type="string" />

  <ParamField body="tool_choice.function" type="object">
    <ParamField body="tool_choice.function.name" type="string" />
  </ParamField>
</ParamField>

<ParamField body="response_format" type="object">
  <ParamField body="response_format.type" type="string">
    허용 값: `text`, `json_object`, `json_schema`
  </ParamField>

  <ParamField body="response_format.json_schema" type="object">
    JSON Schema 정의
  </ParamField>
</ParamField>

<ParamField body="seed" type="integer" />

<ParamField body="reasoning_effort" type="string">
  추론 강도(추론 지원 모델용)

  허용 값: `low`, `medium`, `high`
</ParamField>

<ParamField body="modalities" type="array<string>" />

<ParamField body="audio" type="object">
  <ParamField body="audio.voice" type="string" />

  <ParamField body="audio.format" type="string" />
</ParamField>

## Response

<ResponseField name="id" type="string" />

<ResponseField name="object" type="string">
  예시: `chat.completion`
</ResponseField>

<ResponseField name="created" type="integer" />

<ResponseField name="model" type="string" default="gpt-5.5">
  예시: `gpt-5.5`
</ResponseField>

<ResponseField name="choices" type="array<object>">
  <ResponseField name="choices.index" type="integer" />

  <ResponseField name="choices.message" type="object">
    <ResponseField name="choices.message.role" type="string" required>
      메시지 역할

      허용 값: `system`, `user`, `assistant`, `tool`, `developer`
    </ResponseField>

    <ResponseField name="choices.message.content" type="string or array<object>" required>
      메시지 내용
    </ResponseField>

    <ResponseField name="choices.message.name" type="string">
      발신자 이름
    </ResponseField>

    <ResponseField name="choices.message.tool_calls" type="array<object>">
      <ResponseField name="choices.message.tool_calls.id" type="string" />

      <ResponseField name="choices.message.tool_calls.type" type="string">
        예시: `function`
      </ResponseField>

      <ResponseField name="choices.message.tool_calls.function" type="object" />
    </ResponseField>

    <ResponseField name="choices.message.tool_call_id" type="string">
      도구 호출 ID(tool 역할 메시지용)
    </ResponseField>

    <ResponseField name="choices.message.reasoning_content" type="string">
      추론 내용
    </ResponseField>
  </ResponseField>

  <ResponseField name="choices.finish_reason" type="string">
    허용 값: `stop`, `length`, `tool_calls`, `content_filter`
  </ResponseField>
</ResponseField>

<ResponseField name="usage" type="object">
  <ResponseField name="usage.prompt_tokens" type="integer">
    프롬프트 토큰 수
  </ResponseField>

  <ResponseField name="usage.completion_tokens" type="integer">
    완성 토큰 수
  </ResponseField>

  <ResponseField name="usage.total_tokens" type="integer">
    총 토큰 수
  </ResponseField>

  <ResponseField name="usage.prompt_tokens_details" type="object">
    <ResponseField name="usage.prompt_tokens_details.cached_tokens" type="integer" />

    <ResponseField name="usage.prompt_tokens_details.text_tokens" type="integer" />

    <ResponseField name="usage.prompt_tokens_details.audio_tokens" type="integer" />

    <ResponseField name="usage.prompt_tokens_details.image_tokens" type="integer" />
  </ResponseField>

  <ResponseField name="usage.completion_tokens_details" type="object">
    <ResponseField name="usage.completion_tokens_details.text_tokens" type="integer" />

    <ResponseField name="usage.completion_tokens_details.audio_tokens" type="integer" />

    <ResponseField name="usage.completion_tokens_details.reasoning_tokens" type="integer" />
  </ResponseField>
</ResponseField>

<ResponseField name="system_fingerprint" type="string" />
