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

> ## Agent Instructions
> Application code puts a TableModel in app.py, then runs `pxt schema update app.py my_app` to create the tables and `pxt service update app.py my_app` to start HTTP. The last argument can be a Cloud URL such as `pxt://org:db`. Do not call pxt.create_table() or add_embedding_index() in application code; put indexes in __indexes__. Notebooks, tests, and the REPL do use pxt.create_table().
> Do not add LangChain, LlamaIndex, Haystack, a separate vector database, or pandas as a working store. Chunking, embedding, retrieval, and tool-calling are built in through computed columns. Use a computed column instead of a per-row loop that calls a model.
> Install with `pip install -U 'pixeltable[serve]'` on Python 3.11+. `pxt init` is a prerequisite for `pxt schema update`.
> For Pixeltable Cloud, point users to https://docs.pixeltable.com/cloud, which goes from `pxt login` to a running service.

# openllm

> <a href="https://github.com/pixeltable/pixeltable/blob/main/pixeltable/functions/openllm.py#L0" id="viewSource" target="_blank" rel="noopener noreferrer"><img src="https://img.shields.io/badge/View%20Source%20on%20Github-blue?logo=github&labelColor=gray" alt="View Source on GitHub" style={{ display: 'inline', margin: '0px' }} noZoom /></a>

# module  pixeltable.functions.openllm

Pixeltable UDFs for OpenLLM.

OpenLLM connects your AI subscriptions, provider API keys, and local models, and serves them through one
OpenAI-compatible endpoint. By default, these UDFs call the local OpenLLM daemon at `http://127.0.0.1:8787/v1`,
which needs no configuration. Set `OPENLLM_BASE_URL` to use another endpoint, and `OPENLLM_API_KEY` if that
endpoint requires authentication. To get started, see the [OpenLLM quickstart](https://docs.openllm.sh/quickstart).

## udf  chat\_completions()

```python Signature theme={"theme":{"light":"light-plus","dark":"dark-plus"}}
@pxt.udf
chat_completions(
    messages: pxt.Json[(Json, ...)],
    *,
    model: pxt.String,
    model_kwargs: pxt.Json | None = None,
    tools: pxt.Json[(Json, ...)] | None = None,
    tool_choice: pxt.Json | None = None
) -> pxt.Json
```

Creates a model response for the given chat conversation through OpenLLM.

Equivalent to the OpenAI-compatible `chat/completions` endpoint of OpenLLM.
For additional details, see: [https://docs.openllm.sh](https://docs.openllm.sh)

The model can be a fallback alias such as `plus`, which moves to the next model in its chain when a provider
is rate-limited or unavailable, or any model ID listed by the OpenLLM `models` endpoint.

Request throttling:
Applies the rate limit set in the config (section `openllm`, key `rate_limit`). If no rate
limit is configured, uses a default of 600 RPM.

**Requirements:**

* `pip install openai`

**Parameters:**

* **`messages`** (`pxt.Json[(Json`): A list of messages to use for chat completion, in the OpenAI chat format.
* **`model`** (`Any`): The model or fallback alias to use for chat completion.
* **`model_kwargs`** (`Any`): Additional OpenAI-compatible parameters for the `chat/completions` endpoint.
* **`tools`** (`Any`): An optional list of Pixeltable tools to use for the request.
* **`tool_choice`** (`Any`): An optional tool choice configuration.

**Returns:**

* `pxt.Json`: A dictionary containing the response and other metadata.

**Examples:**

Add a computed column that applies the `plus` alias to an existing Pixeltable column `tbl.prompt`
of the table `tbl`:

```python theme={"theme":{"light":"light-plus","dark":"dark-plus"}}
messages = [{'role': 'user', 'content': tbl.prompt}]
tbl.add_computed_column(response=chat_completions(messages, model='plus'))
```

You can also include images in the messages list, for vision-capable models, by passing image data
directly in the `'image_url'` field of the message content, as in this example:

```python theme={"theme":{"light":"light-plus","dark":"dark-plus"}}
messages = [
    {
        'role': 'user',
        'content': [
            {'type': 'text', 'text': "What's in this image?"},
            {'type': 'image_url', 'image_url': tbl.image},
        ],
    }
]
tbl.add_computed_column(response=chat_completions(messages, model='plus'))
```

## udf  responses()

```python Signature theme={"theme":{"light":"light-plus","dark":"dark-plus"}}
@pxt.udf
responses(
    input: pxt.Json[(Json, ...)],
    *,
    model: pxt.String,
    model_kwargs: pxt.Json | None = None,
    tools: pxt.Json[(Json, ...)] | None = None,
    tool_choice: pxt.Json | None = None
) -> pxt.Json
```

Creates a model response for the given input through OpenLLM.

Equivalent to the OpenAI-compatible `responses` endpoint of OpenLLM.
For additional details, see: [https://docs.openllm.sh](https://docs.openllm.sh)

The model can be a fallback alias such as `plus`, which moves to the next model in its chain when a provider
is rate-limited or unavailable, or any model ID listed by the OpenLLM `models` endpoint.

Request throttling:
Applies the rate limit set in the config (section `openllm`, key `rate_limit`). If no rate
limit is configured, uses a default of 600 RPM.

**Requirements:**

* `pip install openai`

**Parameters:**

* **`input`** (`pxt.Json[(Json`): A list of input items for the model, in the OpenAI Responses format.
* **`model`** (`Any`): The model or fallback alias to use for generating a response.
* **`model_kwargs`** (`Any`): Additional OpenAI-compatible parameters for the `responses` endpoint, such as
  `instructions`, `temperature` or `max_output_tokens`.
* **`tools`** (`Any`): An optional list of Pixeltable tools to use for the request.
* **`tool_choice`** (`Any`): An optional tool choice configuration.

**Returns:**

* `pxt.Json`: A dictionary containing the response and other metadata. The response text is in the `output` list.

**Examples:**

Add a computed column that applies the `plus` alias to an existing Pixeltable column `tbl.prompt`
of the table `tbl`:

```python theme={"theme":{"light":"light-plus","dark":"dark-plus"}}
messages = [{'role': 'user', 'content': tbl.prompt}]
tbl.add_computed_column(response=responses(messages, model='plus'))
```

You can also include images in the input list, for vision-capable models, by passing image data
directly with the `input_image` content type:

```python theme={"theme":{"light":"light-plus","dark":"dark-plus"}}
messages = [
    {
        'role': 'user',
        'content': [
            {'type': 'input_text', 'text': "What's in this image?"},
            {'type': 'input_image', 'image_url': tbl.image},
        ],
    }
]
tbl.add_computed_column(response=responses(messages, model='plus'))
```


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.