Use this file to discover all available pages before exploring further.
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.
A CometAPI account with an active API key — get yours here
1
Install the LlamaIndex CometAPI integration
pip install llama-index-llms-cometapi llama-index
2
Set your API key
from llama_index.llms.cometapi import CometLLMimport osos.environ["COMETAPI_KEY"] = "<COMETAPI_KEY>"api_key = os.getenv("COMETAPI_KEY")
Using environment variables is safer than hardcoding credentials in scripts.
3
Initialize the model and make completion calls
from llama_index.core.llms import ChatMessagellm = CometLLM( api_key=api_key, max_tokens=256, context_window=4096, model="your-model-id",)# Chat callmessages = [ ChatMessage(role="system", content="You are a helpful assistant"), ChatMessage(role="user", content="Say 'Hi' only!"),]resp = llm.chat(messages)print(resp)# Completion callresp = llm.complete("Who is Kaiming He?")print(resp)
4
Enable streaming
Use stream_chat or stream_complete for real-time chunked output:
# Streaming chatmessage = ChatMessage(role="user", content="Tell me what ResNet is")for chunk in llm.stream_chat([message]): print(chunk.delta, end="")# Streaming completionfor chunk in llm.stream_complete("Tell me about Large Language Models"): print(chunk.delta, end="")