Skip to main content
LlamaIndex provides the CometLLM class as a first-class integration with CometAPI. Use it to power RAG pipelines, agents, and LLM chains with any model in CometAPI’s catalog.

Prerequisites

  • Python 3.8+
  • A CometAPI account with an active API key — get yours here
1

Install the LlamaIndex CometAPI integration

2

Set your API key

Using environment variables is safer than hardcoding credentials in scripts.
3

Initialize the model and make completion calls

4

Enable streaming

Use stream_chat or stream_complete for real-time chunked output:
  • Models: See the CometAPI Models page for all available options.
  • Using other models: Initialize with a different current model ID, e.g. CometLLM(api_key=api_key, model="your-model-id", max_tokens=1024).
  • Fine-tuning: Pass temperature and max_tokens directly to CometLLM(...).
  • Error handling: Wrap calls in try/except to catch key errors or network issues.
  • Security: Never commit API keys to version control. Use environment variables.
  • More docs: LlamaIndex documentationCometAPI quick startColab example