> ## 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.

# Menggunakan LiteLLM dengan CometAPI

> Gunakan panduan ini untuk mengonfigurasi LiteLLM dengan CometAPI dengan menetapkan base URL, API key, serta opsi model atau provider.

LiteLLM menyediakan API Python terpadu untuk 100+ provider LLM. CometAPI didukung secara native — gunakan prefix `cometapi/` untuk merutekan request melalui katalog model CometAPI.

## Prasyarat

* Python 3.6+
* Akun CometAPI dengan API key aktif — [dapatkan milik Anda di sini](https://www.cometapi.com/console/token)

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

  <Step title="Set your API key">
    Atur API key sebagai environment variable (disarankan) atau berikan secara inline:

    ```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>
      Gunakan environment variable untuk menghindari hardcoding kredensial sensitif di skrip Anda.
    </Note>
  </Step>

  <Step title="Make a completion call">
    Gunakan format `cometapi/<model-name>` untuk menentukan model. Anda dapat memberikan key melalui environment variable atau secara eksplisit:

    ```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="Async and streaming calls">
    Gunakan `acompletion` dengan `stream=True` untuk respons non-blocking dan real-time:

    ```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="Tips and troubleshooting">
    * **Format model**: Model CometAPI menggunakan prefiks `cometapi/<model-name>`, misalnya `cometapi/your-model-id`. Lihat [halaman Model CometAPI](/id/overview/models) untuk model yang tersedia.
    * **Respons Fine-tuning**: LiteLLM mendukung `temperature`, `max_tokens`, dan `top_p` — tambahkan parameter tersebut ke pemanggilan `completion()` apa pun, misalnya `completion(..., temperature=0.7)`.
    * **Penanganan error**: Bungkus pemanggilan dalam `try/except` untuk menangkap error key yang tidak valid atau masalah jaringan.
    * **Keamanan**: Jangan pernah melakukan commit API key ke version control. Gunakan environment variable atau secrets manager.
    * **Batas laju**: Pantau penggunaan di [konsol CometAPI](https://www.cometapi.com/console).
    * **Dokumentasi lebih lanjut**: [dokumentasi LiteLLM](https://docs.litellm.ai/docs/) — [quick start CometAPI](/id/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": "Gunakan LiteLLM dengan CometAPI",
        "description": "Gunakan panduan ini untuk mengonfigurasi LiteLLM dengan CometAPI dengan menetapkan base URL, API key, serta opsi model atau provider.",
        "step": [
          {
            "@type": "HowToStep",
            "@id": "https://apidoc.cometapi.com/integrations/litellm#step-1",
            "position": 1,
            "name": "Install LiteLLM",
            "text": "Selesaikan langkah Install LiteLLM dalam panduan Gunakan LiteLLM dengan CometAPI."
          },
          {
            "@type": "HowToStep",
            "@id": "https://apidoc.cometapi.com/integrations/litellm#step-2",
            "position": 2,
            "name": "Set your API key",
            "text": "Simpan API key CometAPI Anda di environment variable atau field pengaturan yang digunakan oleh integrasi."
          },
          {
            "@type": "HowToStep",
            "@id": "https://apidoc.cometapi.com/integrations/litellm#step-3",
            "position": 3,
            "name": "Make a completion call",
            "text": "Selesaikan langkah Make a completion call dalam panduan Gunakan LiteLLM dengan CometAPI."
          },
          {
            "@type": "HowToStep",
            "@id": "https://apidoc.cometapi.com/integrations/litellm#step-4",
            "position": 4,
            "name": "Async and streaming calls",
            "text": "Selesaikan langkah Async and streaming calls dalam panduan Gunakan LiteLLM dengan CometAPI."
          }
        ]
      },
      {
        "@type": "BreadcrumbList",
        "itemListElement": [
          {
            "@type": "ListItem",
            "position": 1,
            "name": "Dokumentasi CometAPI",
            "item": "https://apidoc.cometapi.com/"
          },
          {
            "@type": "ListItem",
            "position": 2,
            "name": "Integrasi",
            "item": "https://apidoc.cometapi.com/integrations"
          },
          {
            "@type": "ListItem",
            "position": 3,
            "name": "Gunakan LiteLLM dengan CometAPI",
            "item": "https://apidoc.cometapi.com/integrations/litellm"
          }
        ]
      }
    ]
    }
    `}
</script>
