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

# Chat Completion

> OpenAI 호환 엔드포인트를 사용하여 Chat Completion을 생성합니다

`/chat/completions` 엔드포인트를 사용하여 Chat Completion을 생성하세요. 이 엔드포인트는 메시지 전송 및 응답 수신 시 OpenAI 형식을 따릅니다.

<h2 id="requirements">
  요구 사항
</h2>

Chat Completion을 생성하려면 다음 정보가 필요합니다.

* Inference 서비스 base URL: `https://api.inference.wandb.ai/v1`
* W\&B API 키: `[YOUR-API-KEY]`
* 담당 W\&B 팀 및 프로젝트: `[YOUR-TEAM]/[YOUR-PROJECT]` (선택)
* [사용 가능한 모델](/ko/products/inference/serverless/models) 중 하나의 모델 ID

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

다음 예시는 Python과 `curl`을 사용하여 Chat Completion 요청을 보내는 방법을 보여 줍니다. 자리 표시자 값을 본인의 API 키, 팀 및 프로젝트(선택 사항), 모델 ID로 바꾸세요.

<Tabs>
  <Tab title="Python">
    ```python theme={"system"}
    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={"system"}
    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>

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

요청이 성공하면 다음과 같은 OpenAI 호환 형식의 응답이 반환되며, 여기에는 생성된 assistant 메시지와 토큰 사용량 세부 정보가 포함됩니다.

```json theme={"system"}
{
  "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
  }
}
```
