> ## Documentation Index
> Fetch the complete documentation index at: https://wb-21fd5541-docs-hivemind-launch.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# Chat Completions

> OpenAI 호환 엔드포인트를 사용해 chat completion을 생성합니다

`/chat/completions` 엔드포인트를 사용해 chat completion을 생성합니다. 이 엔드포인트는 메시지를 보내고 응답을 받는 데 OpenAI 형식을 따릅니다.

<div id="requirements">
  ## 요구 사항
</div>

Chat Completion을 생성하려면 다음이 필요합니다:

* Inference 서비스 기본 URL: `https://api.inference.wandb.ai/v1`
* W\&B API 키: `<your-api-key>`
* 선택 사항: 담당 W\&B 팀 및 프로젝트: `<your-team>/<your-project>`
* [사용 가능한 모델](/ko/inference/models)의 모델 ID

<div id="request-examples">
  ## 요청 예시
</div>

<Tabs>
  <Tab title="Python">
    ```python theme={null}
    import openai

    client = openai.OpenAI(
        # 맞춤형 base URL은 Serverless Inference를 가리킵니다
        base_url='https://api.inference.wandb.ai/v1',

        # https://wandb.ai/settings 에서 API 키를 생성하세요
        # 보안을 위해 대신 환경 변수 OPENAI_API_KEY로 설정하는 것이 좋습니다
        api_key="<your-api-key>",

        # 선택 사항: 사용 추적을 위한 팀 및 프로젝트
        project="<your-team>/<your-project>",
    )

    # <model-id>를 사용 가능한 모델 목록의 모델 ID로 바꾸세요
    response = client.chat.completions.create(
        model="<model-id>",
        messages=[
            {"role": "system", "content": "<your-system-prompt>"},
            {"role": "user", "content": "<your-prompt>"}
        ],
    )

    print(response.choices[0].message.content)
    ```
  </Tab>

  <Tab title="Bash">
    ```bash theme={null}
    curl https://api.inference.wandb.ai/v1/chat/completions \
      -H "Content-Type: application/json" \
      -H "Authorization: Bearer <your-api-key>" \
      -H "OpenAI-Project: <your-team>/<your-project>" \
      -d '{
        "model": "<model-id>",
        "messages": [
          { "role": "system", "content": "You are a helpful assistant." },
          { "role": "user", "content": "Tell me a joke." }
        ]
      }'
    ```
  </Tab>
</Tabs>

<div id="response-format">
  ## 응답 형식
</div>

API는 OpenAI 호환 형식의 응답을 반환합니다:

```json theme={null}
{
  "id": "chatcmpl-...",
  "object": "chat.completion",
  "created": 1234567890,
  "model": "meta-llama/Llama-3.1-8B-Instruct",
  "choices": [
    {
      "index": 0,
      "message": {
        "role": "assistant",
        "content": "Here's a joke for you..."
      },
      "finish_reason": "stop"
    }
  ],
  "usage": {
    "prompt_tokens": 25,
    "completion_tokens": 50,
    "total_tokens": 75
  }
}
```
