Usage guide
Setup, environment variables, and Python/JavaScript/Go usage examples.
CometAPILLM
Unified OpenAI-compatible LLM gateway via CometAPI. Routes to many providers’ models behind a single endpoint and key, using the OpenAI chat-completions contract with streaming and tool calling.Constructor
CometAPI key. Falls back to
COMETAPI_API_KEY.Any CometAPI-routed model id (e.g.
"gpt-4o-mini", "claude-...", "gemini-..."). Default "gpt-4o-mini".Override the API base URL. Falls back to
COMETAPI_BASE_URL.Sampling temperature. Default 0.7.
Tool selection mode (
"auto"/"none"/"required").Max tokens to generate. Default 1024.
Nucleus sampling probability mass. Default None.
Penalize token frequency, -2.0–2.0. Default None.
Penalize token presence, -2.0–2.0. Default None.
Seed for reproducible sampling. Default None.
Stop sequence that halts generation. Default None.
Stable end-user identifier. Default None.
Allow multiple tool calls per turn. Default None.
Structured-output spec (e.g.
{"type": "json_object"}).aclose
cancel_current_generation
chat
The conversation history to send to the model.
Optional tool definitions the model may call.
Optional conversational graph guiding the exchange.
LLMResponse: Response chunks produced as the model generates output.
emit
The event to emit.
off
The event the handler was registered for.
The handler to remove.
on
callback is omitted.
The event to listen for.
The handler to invoke when the event is emitted. If
None, a decorator is returned that registers the decorated function.The registered callback when
callback is provided, otherwise a decorator that registers and returns the function it wraps.