> ## Documentation Index
> Fetch the complete documentation index at: https://docs.zeroruntime.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# Cometapi

> Python API reference for the cometapi llm plugin.

<Card title="Usage guide" icon="book" href="/plugins/llm/cometapi" horizontal>
  Setup, environment variables, and Python/JavaScript/Go usage examples.
</Card>

## 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

```python theme={null}
CometAPILLM(*, api_key: 'str | None' = None, model: 'CometAPILLMModel | str' = 'gpt-4o-mini', base_url: 'str | None' = None, temperature: 'float' = 0.7, tool_choice: 'str' = 'auto', max_completion_tokens: 'int | None' = None, top_p: 'float | None' = None, frequency_penalty: 'float | None' = None, presence_penalty: 'float | None' = None, seed: 'int | None' = None, stop: 'str | None' = None, user: 'str | None' = None, parallel_tool_calls: 'bool | None' = None, response_format: 'dict | None' = None, **kwargs) -> 'None'
```

<ParamField path="api_key" type="str | None">
  CometAPI key. Falls back to `COMETAPI_API_KEY`.
</ParamField>

<ParamField path="model" type="CometAPILLMModel | str" default="gpt-4o-mini">
  Any CometAPI-routed model id (e.g. `"gpt-4o-mini"`, `"claude-..."`, `"gemini-..."`). Default `"gpt-4o-mini"`.
</ParamField>

<ParamField path="base_url" type="str | None">
  Override the API base URL. Falls back to `COMETAPI_BASE_URL`.
</ParamField>

<ParamField path="temperature" type="float" default="0.7">
  Sampling temperature. Default 0.7.
</ParamField>

<ParamField path="tool_choice" type="str" default="auto">
  Tool selection mode (`"auto"`/`"none"`/`"required"`).
</ParamField>

<ParamField path="max_completion_tokens" type="int | None">
  Max tokens to generate. Default 1024.
</ParamField>

<ParamField path="top_p" type="float | None">
  Nucleus sampling probability mass. Default None.
</ParamField>

<ParamField path="frequency_penalty" type="float | None">
  Penalize token frequency, -2.0–2.0. Default None.
</ParamField>

<ParamField path="presence_penalty" type="float | None">
  Penalize token presence, -2.0–2.0. Default None.
</ParamField>

<ParamField path="seed" type="int | None">
  Seed for reproducible sampling. Default None.
</ParamField>

<ParamField path="stop" type="str | None">
  Stop sequence that halts generation. Default None.
</ParamField>

<ParamField path="user" type="str | None">
  Stable end-user identifier. Default None.
</ParamField>

<ParamField path="parallel_tool_calls" type="bool | None">
  Allow multiple tool calls per turn. Default None.
</ParamField>

<ParamField path="response_format" type="dict | None">
  Structured-output spec (e.g. `&#123;"type": "json_object"&#125;`).
</ParamField>

### aclose

```python theme={null}
def aclose(self) -> 'None'
```

Release any resources held by the provider.

### cancel\_current\_generation

```python theme={null}
def cancel_current_generation(self) -> 'None'
```

Cancel the in-progress generation for the active session, if any.

### chat

```python theme={null}
def chat(self, messages: 'Any', tools: 'Any' = None, conversational_graph: 'Any' = None, **kwargs: 'Any') -> 'AsyncIterator[LLMResponse]'
```

Generate a streamed chat completion.

<ParamField path="messages" type="Any" required>
  The conversation history to send to the model.
</ParamField>

<ParamField path="tools" type="Any">
  Optional tool definitions the model may call.
</ParamField>

<ParamField path="conversational_graph" type="Any">
  Optional conversational graph guiding the exchange.
</ParamField>

<ResponseField name="returns" type="AsyncIterator[LLMResponse]">
  LLMResponse: Response chunks produced as the model generates output.
</ResponseField>

### emit

```python theme={null}
def emit(self, event: 'T', *args: 'Any') -> 'None'
```

Emit an event, invoking all registered handlers with the given arguments.

Handlers are called in registration order. Coroutine handlers are
scheduled on the running event loop. If the emitter is closed, the call
is a no-op.

<ParamField path="event" type="T" required>
  The event to emit.
</ParamField>

### off

```python theme={null}
def off(self, event: 'T', callback: 'Callable[..., Any]') -> 'None'
```

Remove a previously registered handler for an event.

If the handler is not registered for the event, the call is a no-op.

<ParamField path="event" type="T" required>
  The event the handler was registered for.
</ParamField>

<ParamField path="callback" type="Callable[..., Any]" required>
  The handler to remove.
</ParamField>

### on

```python theme={null}
def on(self, event: 'T', callback: 'Callable[..., Any] | None' = None) -> 'Callable[..., Any]'
```

Register a handler for an event.

Can be used directly by passing a callback, or as a decorator when
`callback` is omitted.

<ParamField path="event" type="T" required>
  The event to listen for.
</ParamField>

<ParamField path="callback" type="Callable[..., Any] | None">
  The handler to invoke when the event is emitted. If `None`, a decorator is returned that registers the decorated function.
</ParamField>

<ResponseField name="returns" type="Callable[..., Any]">
  The registered callback when `callback` is provided, otherwise a decorator that registers and returns the function it wraps.
</ResponseField>

***

## CometAPILLMModel

```python theme={null}
CometAPILLMModel = typing.Literal['gpt-4o-mini', 'gpt-5.5', 'gpt-5.4', 'gpt-5.4-mini', 'gpt-5.4-nano', 'claude-opus-4-8', 'claude-sonnet-4-6', 'gemini-3.5-flash', 'deepseek-v4', 'grok-4-3']
```
