Skip to main content

LlamaIndex LLM Integration: CometAPI

Installation

To install the required packages, run:

pip install llama-index-llms-cometapi

Setup

Get API Key

  1. Visit CometAPI Console
  2. Sign up for an account (If you don't already have a CometAPI account)
  3. Generate your API key

Initialize CometAPI

You can set the API key either as an environment variable COMETAPI_API_KEY or pass it directly:

from llama_index.llms.cometapi import CometAPI

# Method 1: Using environment variable
# export COMETAPI_API_KEY="your-api-key"
llm = CometAPI(model="gpt-4o-mini")

# Method 2: Direct API key
llm = CometAPI(
    api_key="your-api-key",
    model="gpt-4o-mini",
    max_tokens=256,
    context_window=4096,
)

Usage Examples

Generate Chat Responses

from llama_index.core.llms import ChatMessage

message = ChatMessage(role="user", content="Tell me a joke")
resp = llm.chat([message])
print(resp)

Streaming Chat

message = ChatMessage(role="user", content="Tell me a story")
resp = llm.stream_chat([message])
for r in resp:
    print(r.delta, end="")

Text Completion

resp = llm.complete("Tell me a joke")
print(resp)

Streaming Completion

resp = llm.stream_complete("Tell me a story")
for r in resp:
    print(r.delta, end="")

Available Models

CometAPI supports various state-of-the-art models:

GPT Series

  • gpt-5-chat-latest
  • chatgpt-4o-latest
  • gpt-5-mini
  • gpt-4o-mini
  • gpt-4.1-mini

Claude Series

  • claude-opus-4-1-20250805
  • claude-sonnet-4-20250514
  • claude-3-5-haiku-latest

Gemini Series

  • gemini-2.5-pro
  • gemini-2.5-flash
  • gemini-2.0-flash

Others

  • deepseek-v3.1
  • grok-4-0709
  • qwen3-30b-a3b

For complete list, visit: https://api.cometapi.com/pricing

Model Configuration

# Use different models
llm_claude = CometAPI(model="claude-3-5-haiku-latest")
llm_gemini = CometAPI(model="gemini-2.5-flash")
llm_deepseek = CometAPI(model="deepseek-v3.1")

response = llm_claude.complete("Explain quantum computing")
print(response)

Documentation

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

llama_index_llms_cometapi-0.3.1.tar.gz (4.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

llama_index_llms_cometapi-0.3.1-py3-none-any.whl (4.3 kB view details)

Uploaded Python 3

File details

Details for the file llama_index_llms_cometapi-0.3.1.tar.gz.

File metadata

  • Download URL: llama_index_llms_cometapi-0.3.1.tar.gz
  • Upload date:
  • Size: 4.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.12.7 {"installer":{"name":"uv","version":"0.12.7","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for llama_index_llms_cometapi-0.3.1.tar.gz
Algorithm Hash digest
SHA256 19a982a3e15a062eb76eaab4beec9f4c1d8e00dd604278b14f157b4934e9f45d
MD5 3779eb698aee95ced3ef15d5f254e301
BLAKE2b-256 ecae6b438b5fccc46ef22fb5785de105ed99d318bdbf7b36b08c7a54438dad3e

See more details on using hashes here.

File details

Details for the file llama_index_llms_cometapi-0.3.1-py3-none-any.whl.

File metadata

  • Download URL: llama_index_llms_cometapi-0.3.1-py3-none-any.whl
  • Upload date:
  • Size: 4.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.12.7 {"installer":{"name":"uv","version":"0.12.7","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for llama_index_llms_cometapi-0.3.1-py3-none-any.whl
Algorithm Hash digest
SHA256 024e378d2a75788aa3fc3df42fa0e5db86c327b40d6dc01f96d1bee01567b473
MD5 9ffcb381e4850d78451b30b54e7fef9d
BLAKE2b-256 da0b63b84ea048964d8a2b6e7affabbbc444d933db5bee93feec251661fd2994

See more details on using hashes here.

Release history Release notifications | RSS feed

This release

0.3.1 This release

2 files

0.3.0

2 files

0.2.0

2 files

0.1.1

2 files

0.1.0

2 files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page