Skip to main content

CometAPI Python SDK

Stable release line: 0.1.x maintenance releases are available from PyPI.

cometapi is a thin Python adapter over the official OpenAI SDK for the OpenAI-compatible CometAPI endpoint. It changes the default API key and base URL configuration while preserving official OpenAI request, response, stream, error, retry, timeout, proxy, and transport behavior.

Supported 0.1 surface

Operation Synchronous Asynchronous Streaming
chat.completions.create Yes Yes Yes
responses.create Yes Yes Yes
models.list Yes Yes Not applicable

Only these operations are supported and contract-tested for 0.1. Other resources inherited from the OpenAI client are not CometAPI support claims. See COMPATIBILITY.md for the precise compatibility policy.

The package requires Python 3.10 or later and declares openai>=2.45.0,<3.0.0.

Project links: CometAPI, API documentation, source repository, and issue tracker.

Installation

Install the latest stable release from PyPI with:

python -m pip install cometapi

See the CometAPI package on PyPI for the current stable distribution and release history.

Authentication and configuration

Create an API key at https://www.cometapi.com/console/token and provide it through the environment:

export COMETAPI_KEY="your-api-key"

You are responsible for all usage and charges incurred with your key. Never commit a key, place one in an example, or include one in a bug report.

Configuration precedence is explicit constructor value, then environment variable, then the default:

Constructor option Environment variable Default
api_key COMETAPI_KEY Required
base_url COMETAPI_BASE_URL https://api.cometapi.com/v1

Leading and trailing whitespace is removed from string API keys and base URLs. An explicitly blank string is invalid and never falls back to the environment or default. A blank COMETAPI_KEY is treated as missing, while a blank COMETAPI_BASE_URL uses the default CometAPI URL. Callable API keys and httpx.URL values retain their official OpenAI behavior.

Usage

Chat Completions

from cometapi import CometAPI

with CometAPI() as client:
    response = client.chat.completions.create(
        model="gpt-5.6-sol",
        messages=[{"role": "user", "content": "Hello!"}],
    )
    print(response.choices[0].message.content)

Streaming uses the official OpenAI stream type:

from cometapi import CometAPI

with CometAPI() as client:
    stream = client.chat.completions.create(
        model="gpt-5.6-sol",
        messages=[{"role": "user", "content": "Write one sentence."}],
        stream=True,
    )
    for chunk in stream:
        print(chunk.choices[0].delta.content or "", end="")

Responses and Models

from cometapi import CometAPI

with CometAPI() as client:
    response = client.responses.create(
        model="gpt-5.6-sol",
        input="Explain API compatibility in one sentence.",
    )
    models = client.models.list()

print(response.output_text)
print(models.data[0].id if models.data else "No models returned")

Async client

import asyncio

from cometapi import AsyncCometAPI


async def main() -> None:
    async with AsyncCometAPI() as client:
        response = await client.responses.create(
            model="gpt-5.6-sol",
            input="Say hello.",
        )
        print(response.output_text)


asyncio.run(main())

The constructor exposes a named, typed option set: api_key, admin_api_key, organization, project, webhook_secret, base_url, websocket_base_url, timeout, max_retries, default_headers, default_query, and the sync or async http_client. Configure proxies through that documented custom HTTP client path. OpenAI provider routing and workload identity are deliberately excluded because they replace CometAPI routing or authentication; private underscore-prefixed OpenAI controls and arbitrary keywords are rejected. Inherited copy and with_options helpers are not part of the supported 0.1 surface and cannot be used to introduce those excluded routing or authentication options.

Direct OpenAI interoperability

Applications may configure the official client directly when they do not need the CometAPI-specific defaults:

import os

from openai import OpenAI

client = OpenAI(
    api_key=os.environ["COMETAPI_KEY"],
    base_url="https://api.cometapi.com/v1",
)

This is an interoperability option, not the primary cometapi experience.

Explicit non-goals for 0.1

The 0.1 release does not add Anthropic or Gemini adapters, CometAPI account or platform resources, media APIs, provider-neutral message translation, CLI behavior, or custom HTTP/SSE/retry implementations. There are no compatibility aliases named CometClient or AsyncCometClient.

Development

All commands run from this repository root:

uv sync --locked
uv run ruff check src tests scripts
uv run ruff format --check src tests scripts
uv run pyright
uv run pytest -m "not live"
uv run python scripts/check_version.py --require-changelog --require-public-preview-docs
uv run python scripts/check_secrets.py
uv run python scripts/check_workflows.py
rm -rf dist
uv build
uv run twine check dist/*
uv run python scripts/check_artifacts.py dist/*
uv run python scripts/check_clean_install.py dist/*
uv run python scripts/check_repository_independence.py
uv run python scripts/run_actionlint.py

actionlint is static validation, not evidence that a workflow ran successfully on GitHub. See CONTRIBUTING.md and RELEASING.md for the contributor and release gates.

The scheduled/manual trusted smoke checks only the current default branch for ongoing compatibility. It cannot validate or authorize a release. Publication requires a separate protected live job that checks out the exact immutable release commit after default-branch ancestry verification and must succeed before the protected PyPI job becomes eligible.

Support and security

Use the issue tracker for reproducible SDK problems and support@cometapi.com for private support or conduct reports. Use the private security advisory form for vulnerabilities. SUPPORT.md and SECURITY.md define the corresponding scope and handling guidance.

License

MIT. See LICENSE.

Metadata

Release files for cometapi 0.1.4

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

Source distribution (sdist)

Source distribution for cometapi 0.1.4
File Size Uploaded Provenance
cometapi-0.1.4.tar.gz 135.3 kB With provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for cometapi 0.1.4
File Interpreter ABI Platform
cometapi-0.1.4-py3-none-any.whl Python 3 none any Details

Total release size: 142.1 kB

Release files / cometapi-0.1.4.tar.gz

Download URL cometapi-0.1.4.tar.gz
Size 135.3 kB
Tags Source
SHA-256 checksum
How to use checksums
b2b4adbc5da852fe9fdedbe17fa3f29aa536ebb31aefe9d2a7047e783d528df2
BLAKE2b-256 checksum
How to use checksums
c1ab49a030b834a23d7955c515eb81cce6e5e0a75d852c3a7b3bcdf53890868e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.14

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Jul 31, 2026.

Transparency log

Release files / cometapi-0.1.4-py3-none-any.whl

Download URL cometapi-0.1.4-py3-none-any.whl
Size 6.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
fc5992fed080b19e0d656b2f4a4bf5eef7f82b3726ba415f84853b228d4c484c
BLAKE2b-256 checksum
How to use checksums
d065b912a67a24c86eeb4cae797a56ff8320034d7ea1da158f1bb2b2fdf57076
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.14

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Jul 31, 2026.

Transparency log

Security for cometapi 0.1.4

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.

Full provenance

All 2 files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for cometapi-0.1.4.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Jul 31, 2026.

Transparency log

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