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

# CometAPI와 함께 LiteLLM 사용하기

> 이 가이드를 사용해 base URL, API key, 그리고 model 또는 provider 옵션을 설정하여 LiteLLM을 CometAPI와 함께 구성하세요.

LiteLLM은 100개 이상의 LLM provider를 위한 통합 Python API를 제공합니다. CometAPI는 기본적으로 지원되며, `cometapi/` 접두사를 사용해 요청을 CometAPI의 model 카탈로그로 라우팅할 수 있습니다.

## 사전 요구 사항

* Python 3.6+
* 활성 API 키가 있는 CometAPI 계정 — [여기에서 발급받으세요](https://www.cometapi.com/console/token)

<Steps>
  <Step title="LiteLLM 설치">
    ```bash theme={null}
    pip install litellm
    ```
  </Step>

  <Step title="API 키 설정">
    API 키를 환경 변수로 설정하거나(권장) 인라인으로 전달합니다:

    ```python theme={null}
    import os
    from litellm import completion

    # Recommended: environment variable
    os.environ["COMETAPI_KEY"] = "<COMETAPI_KEY>"

    # Alternative: pass inline
    api_key = "<COMETAPI_KEY>"
    ```

    <Note>
      스크립트에 민감한 자격 증명을 하드코딩하지 않도록 환경 변수를 사용하세요.
    </Note>
  </Step>

  <Step title="완성 호출 만들기">
    모델을 지정하려면 `cometapi/<model-name>` 형식을 사용하세요. 키는 환경 변수를 통해 전달하거나 명시적으로 전달할 수 있습니다:

    ```python theme={null}
    messages = [{"content": "Hello, how are you?", "role": "user"}]

    # Method 1: environment variable (recommended)
    response = completion(model="cometapi/your-model-id", messages=messages)

    # Method 2: explicit API key
    response = completion(model="cometapi/your-model-id", messages=messages, api_key=api_key)

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

  <Step title="비동기 및 스트리밍 호출">
    논블로킹 실시간 응답을 위해 `stream=True`와 함께 `acompletion`을 사용하세요:

    ```python theme={null}
    from litellm import acompletion
    import asyncio, traceback

    async def stream_call():
        try:
            response = await acompletion(
          model="cometapi/your-model-id",
                messages=[{"content": "Hello, how are you?", "role": "user"}],
                stream=True,
            )
            async for chunk in response:
                print(chunk)
        except Exception:
            print(f"Error: {traceback.format_exc()}")

    asyncio.run(stream_call())
    ```
  </Step>
</Steps>

<AccordionGroup>
  <Accordion title="팁 및 문제 해결">
    * **모델 형식**: CometAPI 모델은 `cometapi/<model-name>` 접두사를 사용합니다. 예: `cometapi/your-model-id`. 사용 가능한 모델은 [CometAPI Models 페이지](/ko/overview/models)를 참조하세요.
    * **파인튜닝 응답**: LiteLLM은 `temperature`, `max_tokens`, `top_p`를 지원합니다 — 예를 들어 `completion(..., temperature=0.7)`처럼 어떤 `completion()` 호출에도 추가할 수 있습니다.
    * **오류 처리**: 잘못된 키 오류나 네트워크 문제를 잡으려면 호출을 `try/except`로 감싸세요.
    * **보안**: API 키를 버전 관리에 절대 커밋하지 마세요. 환경 변수 또는 secrets manager를 사용하세요.
    * **속도 제한**: [CometAPI 콘솔](https://www.cometapi.com/console)에서 사용량을 모니터링하세요.
    * **추가 문서**: [LiteLLM 문서](https://docs.litellm.ai/docs/) — [CometAPI 빠른 시작](/ko/overview/quick-start)
  </Accordion>
</AccordionGroup>

<script type="application/ld+json">
  {`
    {
    "@context": "https://schema.org",
    "@graph": [
      {
        "@type": "HowTo",
        "@id": "https://apidoc.cometapi.com/integrations/litellm#howto",
        "name": "CometAPI와 함께 LiteLLM 사용하기",
        "description": "이 가이드를 사용해 base URL, API 키, 모델 또는 provider 옵션을 설정하여 CometAPI와 함께 LiteLLM을 구성하세요.",
        "step": [
          {
            "@type": "HowToStep",
            "@id": "https://apidoc.cometapi.com/integrations/litellm#step-1",
            "position": 1,
            "name": "LiteLLM 설치",
            "text": "CometAPI와 함께 LiteLLM 사용하기 가이드에서 LiteLLM 설치 단계를 완료하세요."
          },
          {
            "@type": "HowToStep",
            "@id": "https://apidoc.cometapi.com/integrations/litellm#step-2",
            "position": 2,
            "name": "API 키 설정",
            "text": "통합에서 사용하는 환경 변수 또는 설정 필드에 CometAPI API 키를 저장하세요."
          },
          {
            "@type": "HowToStep",
            "@id": "https://apidoc.cometapi.com/integrations/litellm#step-3",
            "position": 3,
            "name": "완성 호출 만들기",
            "text": "CometAPI와 함께 LiteLLM 사용하기 가이드에서 완성 호출 만들기 단계를 완료하세요."
          },
          {
            "@type": "HowToStep",
            "@id": "https://apidoc.cometapi.com/integrations/litellm#step-4",
            "position": 4,
            "name": "비동기 및 스트리밍 호출",
            "text": "CometAPI와 함께 LiteLLM 사용하기 가이드에서 비동기 및 스트리밍 호출 단계를 완료하세요."
          }
        ]
      },
      {
        "@type": "BreadcrumbList",
        "itemListElement": [
          {
            "@type": "ListItem",
            "position": 1,
            "name": "CometAPI 문서",
            "item": "https://apidoc.cometapi.com/"
          },
          {
            "@type": "ListItem",
            "position": 2,
            "name": "통합",
            "item": "https://apidoc.cometapi.com/integrations"
          },
          {
            "@type": "ListItem",
            "position": 3,
            "name": "CometAPI와 함께 LiteLLM 사용하기",
            "item": "https://apidoc.cometapi.com/integrations/litellm"
          }
        ]
      }
    ]
    }
    `}
</script>
