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

Metadata

Release files for llama-index-llms-cometapi 0.3.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for llama-index-llms-cometapi 0.3.1
File Size Uploaded Provenance Actions
llama_index_llms_cometapi-0.3.1.tar.gz 4.0 kB Without provenance Details for llama_index_llms_cometapi-0.3.1.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for llama-index-llms-cometapi 0.3.1
File Interpreter ABI Platform Actions
llama_index_llms_cometapi-0.3.1-py3-none-any.whl Python 3 none any Details for llama_index_llms_cometapi-0.3.1-py3-none-any.whl

Total release size: 8.3 kB

Release files / llama_index_llms_cometapi-0.3.1.tar.gz

Download URL llama_index_llms_cometapi-0.3.1.tar.gz
Size 4.0 kB
Tags Source
SHA-256 checksum
How to use checksums
19a982a3e15a062eb76eaab4beec9f4c1d8e00dd604278b14f157b4934e9f45d
BLAKE2b-256 checksum
How to use checksums
ecae6b438b5fccc46ef22fb5785de105ed99d318bdbf7b36b08c7a54438dad3e
Upload date
Uploaded using Trusted Publishing?
What is 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}

Release files / llama_index_llms_cometapi-0.3.1-py3-none-any.whl

Download URL llama_index_llms_cometapi-0.3.1-py3-none-any.whl
Size 4.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
024e378d2a75788aa3fc3df42fa0e5db86c327b40d6dc01f96d1bee01567b473
BLAKE2b-256 checksum
How to use checksums
da0b63b84ea048964d8a2b6e7affabbbc444d933db5bee93feec251661fd2994
Upload date
Uploaded using Trusted Publishing?
What is 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}

Security for llama-index-llms-cometapi 0.3.1

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

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