# AI

> AI: models paid from your NoClick balance, for code that isn't an agent, and your agents as models.

```python
reply = noclick.AI.chat("Summarize this in one line: ...")
vectors = noclick.AI.embed(["first", "second"]).vectors
image = noclick.AI.image("A lighthouse at dusk, watercolor")
clip = noclick.AI.video("Waves rolling under a lighthouse at dusk").wait()
words = noclick.AI.transcribe("https://example.com/call.mp3")
answer = noclick.AI.chat("Where's my refund?", model="agent:support")
```

Every call is charged in US dollars to your account; inside `as_user` it is
attributed to that user and counts against its spend cap. `AI.base_url`
serves chat completions, responses, embeddings and the model list to any
OpenAI client.

## noclick.AI

```python
class AI
```

Models paid from your NoClick balance, for code that isn't an agent: chat,
embeddings, images, videos and transcription; and your agents as `agent:<name>`
models. Model ids are OpenRouter ids with the `openrouter/` prefix, except
transcription's, NoClick's own `noclick/transcribe-1`; leave `model` out for
NoClick's default of each kind.

| Attribute | Type | Description |
| --- | --- | --- |
| `base_url` | `str` | The OpenAI-compatible endpoint (`https://api.noclick.com/v1/ai` on the hosted API): point any OpenAI client at it with your NoClick key for chat completions, responses, embeddings and the model list. |

### AI.chat

```python
noclick.AI.chat(
    messages, *, model=None, max_tokens=None, temperature=None, response_format=None,
    tools=None, tool_choice=None, reasoning_effort=None, conversation=None, user=...,
    client=None
) -> ChatReply
```

Send a conversation to a chat model: a list of `{"role", "content"}`
messages, or a string as one user message. `response_format` asks for JSON
(`{"type": "json_schema", "json_schema": ...}`); `tools` are OpenAI-format
tool definitions, such as `toolkit.definitions("openai")`, and `tool_choice`
says which the model calls: `auto` (its choice), `none`, `required` (one of
them), or one by name (`{"type": "function", "function": {"name": "submit"}}`).

`reasoning_effort` sets how hard a model that reasons thinks first, among its
`reasoning.efforts` in `AI.models`: its reasoning counts toward `max_tokens`,
so a lower effort leaves more of them for the answer, and `none` turns it off
where the model can stop. A field the model doesn't list in its `parameters` has
no effect.

`model="agent:<name>"` talks to one of your agents instead, which brings its
own tools (so `tools` is refused) and keeps the conversation: pass
`conversation=reply.conversation` to continue it, and only the messages after
the last assistant message are sent. The answer streams, so a long turn never
times out. A request with no conversation whose messages end in an assistant
reply the agent gave recently continues that reply's conversation (in the same
user), so a chat UI that resends the whole history keeps one thread (invite-only
beta).

Parameters:

- `messages` (`str | Sequence[Any]`, required)
- `model` (`str | None`, default `None`)
- `max_tokens` (`int | None`, default `None`)
- `temperature` (`float | None`, default `None`)
- `response_format` (`dict[str, Any] | None`, default `None`)
- `tools` (`Sequence[dict[str, Any]] | None`, default `None`)
- `tool_choice` (`str | dict[str, Any] | None`, default `None`)
- `reasoning_effort` (`str | None`, default `None`)
- `conversation` (`str | None`, default `None`)
- `user` (`Any`, default: the current user): Who the call acts for. Defaults to the user set by `noclick.as_user` (none: the account itself).
- `client` (`Client | None`, default `None`): The client to send with; defaults to the module client built from `NOCLICK_API_KEY`.

Returns: `ChatReply` The answer: its `text`, the `message` to append to the conversation, and
the tokens it used and what it cost.

Usage:

Ask for one answer:

```python
reply = noclick.AI.chat(
    [
        {"role": "system", "content": "You write one-line summaries."},
        {"role": "user", "content": "Summarize: the meeting moved to Friday at 3pm."},
    ],
    model="openrouter/anthropic/claude-sonnet-4.6",
    max_tokens=200,
)
print(reply.text, reply.cost_usd)
```

Let the model use your users' connections, with a `Toolkit`:

```python
toolkit = noclick.Toolkit(["gmail", "search"])
messages = [{"role": "user", "content": "Summarize the emails Ana sent me this week"}]
with noclick.as_user("user_42"):
    while True:
        reply = noclick.AI.chat(messages, tools=toolkit.definitions("openai"))
        messages.append(reply.message)
        if not reply.tool_calls:
            break
        messages += toolkit.handle_openai(reply.message)
print(reply.text)
```

Talk to one of your agents, then keep going in its conversation:

```python
reply = noclick.AI.chat("Where's my refund?", model="agent:support")
follow_up = noclick.AI.chat("And how long will it take?", model="agent:support",
                            conversation=reply.conversation)
print(follow_up.text)
```

### AI.embed

```python
noclick.AI.embed(
    texts, *, model=None, dimensions=None, user=..., client=None
) -> Embeddings
```

Turn text into vectors for search and clustering: one string, or a list of
up to 2,048. `dimensions` shortens the vectors, for models that allow it.

Parameters:

- `texts` (`str | Sequence[str]`, required)
- `model` (`str | None`, default `None`)
- `dimensions` (`int | None`, default `None`)
- `user` (`Any`, default: the current user): Who the call acts for. Defaults to the user set by `noclick.as_user` (none: the account itself).
- `client` (`Client | None`, default `None`): The client to send with; defaults to the module client built from `NOCLICK_API_KEY`.

Returns: `Embeddings` One vector per text, in order, with their length and what the call cost.

Usage:

```python
docs = ["Refunds take 5 days.", "We ship worldwide.", "Support is open 9 to 5."]
result = noclick.AI.embed(docs, model="openrouter/openai/text-embedding-3-small")
print(result.dimensions, len(result.vectors))   # 1536 3

[query] = noclick.AI.embed("How long do refunds take?", model="openrouter/openai/text-embedding-3-small").vectors
```

### AI.image

```python
noclick.AI.image(
    prompt, *, model=None, size=None, images=None, user=..., client=None
) -> GeneratedImage
```

Make one image from `prompt`; `size` is `"WIDTHxHEIGHT"` in an aspect
ratio the model makes (the model's own shape unless you say). `images` are pictures
(URLs, up to 8) to make it from: one to edit, the prompt saying what to change, or
several to combine.

Parameters:

- `prompt` (`str`, required)
- `model` (`str | None`, default `None`)
- `size` (`str | None`, default `None`)
- `images` (`Sequence[str] | None`, default `None`)
- `user` (`Any`, default: the current user): Who the call acts for. Defaults to the user set by `noclick.as_user` (none: the account itself).
- `client` (`Client | None`, default `None`): The client to send with; defaults to the module client built from `NOCLICK_API_KEY`.

Returns: `GeneratedImage` The image, kept as one of your account's files: a `url` that keeps working, its
`file_id`, its size and what it cost.

Usage:

```python
image = noclick.AI.image("A lighthouse at dusk, watercolor", size="1024x1536")
print(image.url, image.width, image.height, image.cost_usd)
night = noclick.AI.image("Make it night", images=[image.url])
```

### AI.video

```python
noclick.AI.video(
    prompt, *, model=None, seconds=None, resolution=None, aspect_ratio=None,
    audio=True, first_frame=None, user=..., client=None
) -> Operation
```

Start one video from `prompt`. It takes minutes, so it runs as an operation.
`seconds`, `resolution` (`720p`, `1080p`) and `aspect_ratio` (`16:9`,
`9:16`) are among the ones the model makes; left out, about 8 seconds at 720p.
`audio` adds sound where the model makes it. `first_frame` is a picture the video
starts from, to bring a photo to life: one of your account's files by its id, or a
JPEG, PNG or WebP image's https URL, up to 10 MB, on a model whose `frame_images`
list `first_frame` (`AI.models(kind="video")`). Its price is quoted before it starts
(`usd_per_second` in `AI.models(kind="video")`) and charged when it's done.

Parameters:

- `prompt` (`str`, required)
- `model` (`str | None`, default `None`)
- `seconds` (`int | None`, default `None`)
- `resolution` (`str | None`, default `None`)
- `aspect_ratio` (`str | None`, default `None`)
- `audio` (`bool`, default `True`)
- `first_frame` (`str | None`, default `None`)
- `user` (`Any`, default: the current user): Who the call acts for. Defaults to the user set by `noclick.as_user` (none: the account itself).
- `client` (`Client | None`, default `None`): The client to send with; defaults to the module client built from `NOCLICK_API_KEY`.

Returns: `Operation` An `Operation` at once, whose `wait()` gives the `GeneratedVideo`, kept as one
of your account's files.

Usage:

```python
job = noclick.AI.video("Waves rolling under a lighthouse at dusk", seconds=8, aspect_ratio="9:16")
clip = job.wait(timeout=600)
print(clip.url, clip.seconds, clip.cost_usd)
waving = noclick.AI.video("She turns and waves", first_frame="https://example.com/me.jpg").wait()
```

### AI.transcribe

```python
noclick.AI.transcribe(
    audio, *, model=None, language=None, speakers=False, background=False, user=...,
    client=None
) -> Transcript | Operation
```

Write down what is said in a recording: an `https` URL to it, or its bytes,
up to 2 hours (25 MB as bytes, 200 MB behind a URL), in MP3, WAV, M4A, MP4, OGG, WebM,
AAC, FLAC or AIFF. `language` (an ISO 639-1 code) skips detection. It runs on
`noclick/transcribe-1`, which takes the whole recording in one call and gives a segment
per sentence, priced per minute of audio as `usd_per_minute` in `AI.models`.

`speakers` tells the voices apart, at the same price, each voice keeping its label from
start to end, and gives a segment per voice's turn. `True` labels each segment's
`speaker` `speaker_1`, `speaker_2` and on, in the order they first speak. A list of
names (`["rep", "customer"]`) says how many voices there are, and NoClick works out
which is which from what they say (a rep introduces the company, say); a voice it can't
tell takes the next unused name in speaking order.

`background=True` returns an `Operation` at once: for a recording that may take
longer than one request waits (90 seconds), as a very long one can (forty minutes usually
take about 20 seconds). A call that doesn't run in the background and passes 90 seconds
raises `RequestTimeout` naming its operation, which still finishes, is charged, and
holds the transcript.

Parameters:

- `audio` (`str | bytes`, required)
- `model` (`str | None`, default `None`)
- `language` (`str | None`, default `None`)
- `speakers` (`bool | Sequence[str]`, default `False`)
- `background` (`bool`, default `False`)
- `user` (`Any`, default: the current user): Who the call acts for. Defaults to the user set by `noclick.as_user` (none: the account itself).
- `client` (`Client | None`, default `None`): The client to send with; defaults to the module client built from `NOCLICK_API_KEY`.

Returns: `Transcript | Operation` The transcript: its `text`, timed `segments`, the `language` and how long the audio
was. With `background=True`, an `Operation` at once, whose `wait()` gives it.

Usage:

From a URL:

```python
words = noclick.AI.transcribe("https://example.com/calls/2026-09-26.mp3")
print(words.language, words.duration_s)
print(words.text)
```

From a file you have:

```python
with open("voicemail.m4a", "rb") as f:
    words = noclick.AI.transcribe(f.read(), language="en")
for segment in words.segments:
    print(f"{segment.start_s:6.1f}s  {segment.text}")
```

Who said what on a sales call:

```python
call = noclick.AI.transcribe("https://example.com/calls/demo.mp3", speakers=["rep", "customer"])
for segment in call.segments:
    print(segment.speaker, segment.text)
```

A two-hour meeting, in the background:

```python
job = noclick.AI.transcribe("https://example.com/meetings/all-hands.mp3", speakers=True,
                            background=True)
meeting = job.wait()
print(len(meeting.segments), meeting.cost_usd)
```

### AI.headers

```python
noclick.AI.headers(*, user=..., client=None) -> dict[str, str]
```

The headers a call to `AI.base_url` needs: your key as the bearer and, inside
`as_user` (or with `user=`), the `NoClick-User` that attributes the call to
that user and holds it to the user's spend cap. Give them to an OpenAI client as
`default_headers`; without the user header the account pays and no user's cap
applies. A client from a user session gets the session's token.

Parameters:

- `user` (`Any`, default: the current user): Who the call acts for. Defaults to the user set by `noclick.as_user` (none: the account itself).
- `client` (`Client | None`, default `None`): The client to send with; defaults to the module client built from `NOCLICK_API_KEY`.

Returns: `dict[str, str]` `Authorization` and, when a user is in scope, `NoClick-User`.

Usage:

One OpenAI client per user, talking to that user's agent:

```python
from openai import OpenAI

with noclick.as_user("user_42"):
    headers = noclick.AI.headers()   # the key rides in these, so api_key is a placeholder
gpt = OpenAI(base_url=noclick.AI.base_url, api_key="-", default_headers=headers)
reply = gpt.chat.completions.create(model="agent:assistant", messages=[{"role": "user", "content": "Hi"}])
```

### AI.models

```python
noclick.AI.models(
    *, kind=None, q=None, model=None, user=..., client=None
) -> list[AIModel]
```

The models you can call (`kind`: `chat`, `embedding`, `image`,
`transcription`, `video` or `agent`); `agent` lists the agents you (or the user
you act for) can talk to as `agent:<name>`. `q` keeps those whose id or name contains
it (any case), `model` the one with that id (`openrouter/` may be left out).

Parameters:

- `kind` (`str | None`, default `None`)
- `q` (`str | None`, default `None`)
- `model` (`str | None`, default `None`)
- `user` (`Any`, default: the current user): Who the call acts for. Defaults to the user set by `noclick.as_user` (none: the account itself).
- `client` (`Client | None`, default `None`): The client to send with; defaults to the module client built from `NOCLICK_API_KEY`.

Returns: `list[AIModel]` Every matching model with its prices in US dollars, the default of each kind first.

Usage:

```python
for m in noclick.AI.models(kind="chat"):
    print(m.id, m.context_length, m.input_usd_per_token, m.output_usd_per_token)
[sonnet] = noclick.AI.models(model="anthropic/claude-sonnet-4.6")
```

## noclick.ChatReply

```python
class ChatReply
```

A model's (or an agent's) answer: `text`, and the whole `message` to
append to the conversation.

| Attribute | Type | Description |
| --- | --- | --- |
| `text` | `str` | The answer as text (empty when the model only called tools). |
| `message` | `dict[str, Any]` | The assistant message as the API sent it (`role`, `content`, `tool_calls`). |
| `model` | `str | None` |  |
| `finish_reason` | `str | None` | Why the model stopped: `stop`, `length` (`max_tokens` reached, reasoning included: a model that spends them all reasoning answers with an empty `text`) or `tool_calls`. |
| `usage` | `dict[str, int]` | Tokens used: `prompt_tokens`, `completion_tokens`, `total_tokens`, and `reasoning_tokens`, the part of `completion_tokens` spent reasoning, where the model reports it (none for an agent). |
| `cost_usd` | `float | None` | What the call cost, in US dollars. |
| `raw` | `dict[str, Any]` | The response JSON exactly as the API sent it. |
| `reasoning` | `str | None` | What the model thought before it answered, where its provider returns it (None otherwise). Reasoning counts toward `max_tokens`: `usage["reasoning_tokens"]` says how much of them it took. |
| `tool_calls` | `list[dict[str, Any]]` | The tools the model asked to call (empty if none), in the OpenAI shape `toolkit.handle_openai` runs. An agent runs its own tools, so its reply never has any. |
| `conversation` | `str | None` | An agent's conversation this reply is part of: pass it as `conversation=` to continue it. |

## noclick.Embeddings

```python
class Embeddings
```

One vector per input, in the order you passed them.

| Attribute | Type | Description |
| --- | --- | --- |
| `vectors` | `list[list[float]]` |  |
| `dimensions` | `int` | The length of each vector. |
| `model` | `str | None` |  |
| `usage` | `dict[str, int]` | Tokens used: `prompt_tokens`, `total_tokens`. |
| `cost_usd` | `float | None` | What the call cost, in US dollars. |
| `raw` | `dict[str, Any]` | The response JSON exactly as the API sent it. |

## noclick.GeneratedImage

```python
class GeneratedImage
```

An image a model made, kept as one of your account's files.

| Attribute | Type | Description |
| --- | --- | --- |
| `url` | `str` | A link to the image that keeps working. |
| `width` | `int | None` |  |
| `height` | `int | None` |  |
| `model` | `str | None` |  |
| `cost_usd` | `float | None` | What the image cost, in US dollars. |
| `expires_at` | `Any` | When `url` stops working: `None`, since the file is kept. |
| `file_id` | `str | None` | The file in your account's files. |
| `raw` | `dict[str, Any]` | The response JSON exactly as the API sent it. |

## noclick.GeneratedVideo

```python
class GeneratedVideo
```

A video a model made, kept as one of your account's files.

| Attribute | Type | Description |
| --- | --- | --- |
| `url` | `str` | A link to the video that keeps working. |
| `file_id` | `str | None` | The file in your account's files. |
| `mime_type` | `str | None` |  |
| `seconds` | `int | None` |  |
| `resolution` | `str | None` |  |
| `model` | `str | None` |  |
| `cost_usd` | `float | None` | What the video cost, in US dollars. |
| `raw` | `dict[str, Any]` | The response JSON exactly as the API sent it. |

## noclick.Transcript

```python
class Transcript
```

What was said in a recording, as one `text` and as timed `segments`.

| Attribute | Type | Description |
| --- | --- | --- |
| `text` | `str` |  |
| `language` | `str | None` | The spoken language as an ISO 639-1 code (`en`), detected unless you passed one; ISO 639-3 (`yue`) for a language with no two-letter code. |
| `duration_s` | `float | None` |  |
| `segments` | `list[TranscriptSegment]` |  |
| `model` | `str | None` |  |
| `cost_usd` | `float | None` | What the transcription cost, in US dollars. |
| `raw` | `dict[str, Any]` | The response JSON exactly as the API sent it. |

## noclick.TranscriptSegment

```python
class TranscriptSegment
```

A stretch of speech: what was said between `start_s` and `end_s`, and by
whom when you asked for `speakers`.

| Attribute | Type | Description |
| --- | --- | --- |
| `start_s` | `float` |  |
| `end_s` | `float` |  |
| `text` | `str` |  |
| `speaker` | `str | None` | Who said it: one of the names you gave `speakers`, or `speaker_1`, `speaker_2`, ... in the order the voices first speak (None unless you asked). |

## noclick.AIModel

```python
class AIModel
```

A model you can call, and what it costs in US dollars (its provider's
own price). Only the prices for its `kind` are set: per token for
`chat` and `embedding` models, per token of the image an `image` model
makes, per minute of audio for `transcription` ones, per second for
`video` ones, and none for an
`agent`, whose turns cost what its model and tools do.

| Attribute | Type | Description |
| --- | --- | --- |
| `id` | `str` | The id to pass as `model=`, like `openrouter/anthropic/claude-sonnet-4.6` or `agent:support`. |
| `name` | `str | None` |  |
| `kind` | `str` | `chat`, `embedding`, `image`, `transcription` or `agent`. |
| `context_length` | `int | None` | The most tokens a request can hold (chat and embedding models). |
| `input_usd_per_token` | `float | None` |  |
| `output_usd_per_token` | `float | None` |  |
| `usd_per_minute` | `float | None` |  |
| `usd_per_minute_with_speakers` | `float | None` | What a minute of audio costs with `speakers`; None for a model of another kind. |
| `usd_per_second` | `float | None` | What a second of video costs, for the clip a call naming no length or resolution makes. |
| `parameters` | `list[str] | None` | The request fields a chat model takes, as its provider lists them (`tools`, `tool_choice`, `reasoning_effort`, `temperature`, ...): one it doesn't list has no effect. None for other kinds. |
| `reasoning` | `AIReasoning | None` | How a chat model reasons; None for one that doesn't. |
| `frame_images` | `list[str] | None` | The frames a video model can start or end on a picture (`first_frame`, `last_frame`): one listing `first_frame` takes `AI.video(first_frame=...)`. None for other kinds. |
| `raw` | `dict[str, Any]` | The response JSON exactly as the API sent it. |

## noclick.AIReasoning

```python
class AIReasoning
```

How a chat model reasons before it answers. Its reasoning counts toward `max_tokens`, so a short
budget can go entirely on reasoning and leave the answer empty (`finish_reason` `length`).

| Attribute | Type | Description |
| --- | --- | --- |
| `mandatory` | `bool` | It always reasons, whatever `reasoning_effort` says. Anthropic's models refuse a forced tool (`tool_choice` `required` or naming a function) while they reason, so on one of theirs that always does, only `auto` and `none` work. |
| `efforts` | `list[str]` | The `reasoning_effort` values it takes (`none` among them where it can stop reasoning). |
| `default_effort` | `str | None` | Its effort when a call names none. |
