# AI models

> Chat, embeddings, images, videos and transcription paid from your NoClick balance, an OpenAI-compatible endpoint, and your agents as models.

`noclick.AI` calls models directly, for the parts of your product that aren't an [agent](https://www.noclick.com/docs/guide/agents.md): a summary, a classification, a search index, a generated image or video, a transcript. Every call is paid from your NoClick balance in US dollars, so you don't need a key with each model provider, and it is attributed like everything else: to the key, and inside `as_user` to the user.

## Chat

```python
import noclick

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)       # The meeting is now Friday at 3pm.
print(reply.usage, reply.cost_usd)
```

```ts
import { AI } from "noclick";

const reply = await 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", maxTokens: 200 },
);
console.log(reply.text);       // The meeting is now Friday at 3pm.
console.log(reply.usage, reply.costUsd);
```

`messages` is a list of `{"role", "content"}` messages, or a plain string as one user message. `model` is an OpenRouter id with an `openrouter/` prefix, as for [agents](https://www.noclick.com/docs/guide/agents.md); leave it out for NoClick's default. `reply.message` is the whole assistant message, ready to append to the conversation for the next turn.

### Leave room for reasoning

A model that reasons thinks before it answers, and its thinking counts toward `max_tokens`. One that spends them all thinking answers with an empty `text`, `finish_reason` `"length"` and `usage["reasoning_tokens"]` equal to `usage["completion_tokens"]`, and those tokens are charged like any others:

```python
reply = noclick.AI.chat("Plan three days in Lisbon.", model="openrouter/anthropic/claude-sonnet-5.5", max_tokens=500)
if reply.finish_reason == "length" and not reply.text:
    print(reply.usage["reasoning_tokens"])   # 500: it was still thinking
```

```ts
import { AI } from "noclick";

const reply = await AI.chat("Plan three days in Lisbon.", { model: "openrouter/anthropic/claude-sonnet-5.5", maxTokens: 500 });
if (reply.finishReason === "length" && !reply.text) {
  console.log(reply.usage.reasoning_tokens);   // 500: it was still thinking
}
```

Give it more room, or ask it to think less: `reasoning_effort` takes one of the efforts the model lists (`"low"`, or `"none"` where it can stop thinking; see [Pick a model](https://www.noclick.com/docs/guide/ai.md#pick-a-model)). `reply.reasoning` holds what it thought, where its provider returns that.

Ask for JSON with `response_format`. NoClick's default model holds a schema strictly, as OpenAI's models do: every property is in `required`, and `additionalProperties` is false.

```python
reply = noclick.AI.chat(
    "Extract the date and time from: the meeting moved to Friday at 3pm.",
    response_format={
        "type": "json_schema",
        "json_schema": {"name": "when", "strict": True, "schema": {
            "type": "object",
            "properties": {"day": {"type": "string"}, "time": {"type": "string"}},
            "required": ["day", "time"],
            "additionalProperties": False,
        }},
    },
)
print(reply.text)   # {"day": "Friday", "time": "15:00"}
```

```ts
import { AI } from "noclick";

const reply = await AI.chat("Extract the date and time from: the meeting moved to Friday at 3pm.", {
  responseFormat: {
    type: "json_schema",
    json_schema: { name: "when", strict: true, schema: {
      type: "object",
      properties: { day: { type: "string" }, time: { type: "string" } },
      required: ["day", "time"],
      additionalProperties: false,
    } },
  },
});
console.log(reply.text);   // {"day": "Friday", "time": "15:00"}
```

## Give it your users' tools

`tools` takes OpenAI-format definitions, so a [toolkit](https://www.noclick.com/docs/guide/toolkits.md) plugs straight in: the model acts in the user's connections, under your [policy](https://www.noclick.com/docs/guide/policy.md).

```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)
```

```ts
import { AI, Toolkit, asUser, type AIChatMessage, type ChatReply } from "noclick";

const toolkit = new Toolkit(["gmail", "search"]);
const messages: AIChatMessage[] = [{ role: "user", content: "Summarize the emails Ana sent me this week" }];
const reply = await asUser("user_42", async () => {
  while (true) {
    const reply: ChatReply = await AI.chat(messages, { tools: await toolkit.definitions({ format: "openai" }) });
    messages.push(reply.message);
    if (!reply.toolCalls.length) return reply;
    // handleOpenAI also answers the Responses API, so name the Chat Completions form it gives here
    messages.push(...((await toolkit.handleOpenAI(reply.message)) as AIChatMessage[]));
  }
});
console.log(reply.text);
```

If you'd rather NoClick ran that loop, keep its state and answer on channels, use an [agent](https://www.noclick.com/docs/guide/agents.md) instead.

`tool_choice` makes the model call one: `"required"` for any of `tools`, or one by name, so a loop can always end in a structured answer:

```python
submit = {"type": "function", "function": {"name": "submit", "parameters": {
    "type": "object", "properties": {"answer": {"type": "string"}}, "required": ["answer"]}}}
reply = noclick.AI.chat("What's 17 times 23?", tools=[submit],
                        tool_choice={"type": "function", "function": {"name": "submit"}})
print(reply.tool_calls[0]["function"]["arguments"])   # {"answer": "391"}
```

```ts
import { AI } from "noclick";

const submit = { type: "function", function: { name: "submit", parameters: {
  type: "object", properties: { answer: { type: "string" } }, required: ["answer"] } } };
const reply = await AI.chat("What's 17 times 23?", {
  tools: [submit], toolChoice: { type: "function", function: { name: "submit" } },
});
console.log((reply.toolCalls[0].function as { arguments: string }).arguments);   // {"answer": "391"}
```

Some models refuse to be made to call a tool while they reason: [Pick a model](https://www.noclick.com/docs/guide/ai.md#pick-a-model) says which.

## Check a translation with a second call

A model that writes in another language and translates its own words in the same call translates what it meant, not what it wrote, so the translation hides its mistakes: a phrase that says "there's a problem" can come back glossed as "no problem". To check what a message says, ask a second call that sees only the words:

```python
draft = noclick.AI.chat("Tell the guest, in Portuguese, that check-in is at 3pm and the pool is closed today.")
gloss = noclick.AI.chat([
    {"role": "system", "content": "Translate the message into English as written. Don't correct or explain it."},
    {"role": "user", "content": draft.text},
])
print(gloss.text)   # what the guest will read
```

```ts
import { AI } from "noclick";

const draft = await AI.chat("Tell the guest, in Portuguese, that check-in is at 3pm and the pool is closed today.");
const gloss = await AI.chat([
  { role: "system", content: "Translate the message into English as written. Don't correct or explain it." },
  { role: "user", content: draft.text },
]);
console.log(gloss.text);   // what the guest will read
```

Compare `gloss.text` with what you meant, by eye or with a third call that sees both, before you send `draft.text`. The checking call can run on a cheaper model: what matters is that it never saw the intent.

## Embeddings

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

```ts
import { AI } from "noclick";

const docs = ["Refunds take 5 days.", "We ship worldwide.", "Support is open 9 to 5."];
const result = await AI.embed(docs, { model: "openrouter/openai/text-embedding-3-small" });
console.log(result.dimensions, result.vectors.length);   // 1536 3
```

One vector per text, in the order you passed them; up to 2,048 texts a call. `dimensions` shortens the vectors for models that allow it. To search them, keep them in a Postgres [database](https://www.noclick.com/docs/guide/databases.md#search-by-meaning) beside the text they came from.

## Images

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

```ts
import { AI } from "noclick";

const image = await AI.image("A lighthouse at dusk, watercolor", { size: "1024x1536" });
console.log(image.url, image.width, image.height, image.costUsd);
```

One image per call, kept as a file in your account (your Files in the app): its `url` keeps working, and `file_id` names it. `size` is `"WIDTHxHEIGHT"` in an aspect ratio the model makes (`1024x1536` is 2:3); a size the model can't make fails with `noclick.InvalidRequest` naming the ratios it can.

## Videos

A video takes minutes, so `noclick.AI.video` returns an [operation](https://www.noclick.com/docs/guide/operations.md) at once, and its `wait()` gives the video:

```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.resolution, clip.cost_usd)
```

```ts
import { AI } from "noclick";

const job = await AI.video("Waves rolling under a lighthouse at dusk", { seconds: 8, aspectRatio: "9:16" });
const clip = await job.wait({ timeoutS: 600 });
console.log(clip.url, clip.seconds, clip.resolution, clip.costUsd);
```

Like an image, the video is kept as a file in your account (`url`, `file_id`). `seconds`, `resolution` (`720p`, `1080p`) and `aspect_ratio` (`16:9`, `9:16`) are among the ones the model makes; leave them out for about 8 seconds at 720p. `audio=False` leaves the sound out, where the model makes it. Only models priced per second can be used, since the price is quoted before the video starts: a call your balance can't cover is refused then, with nothing charged, and the video is charged at that cost when it's done. A length or shape the model can't make fails with `noclick.InvalidRequest` naming the ones it can. Keep `job.id` to pick the video up later, from anywhere (`noclick.Operation.from_id(job.id).wait()`).

### Start from a picture

`first_frame` brings a photo to life: the video opens on that picture and moves on from it.

```python
photo = noclick.AI.image("A ceramic mug on a sunlit kitchen table")
clip = noclick.AI.video("Steam rises from the mug as the light shifts", first_frame=photo.url).wait(timeout=600)
```

```ts
import { AI } from "noclick";

const photo = await AI.image("A ceramic mug on a sunlit kitchen table");
const job = await AI.video("Steam rises from the mug as the light shifts", { firstFrame: photo.url });
const clip = await job.wait({ timeoutS: 600 });
```

The picture is one of your account's files, by its id (a file someone sent your agent, or an image you made: its `file_id`), or any JPEG, PNG or WebP image's https URL, up to 10 MB. Only the models whose `frame_images` list `first_frame` start from a picture (`noclick.AI.models(kind="video")`); the default does, and a model that can't fails with `noclick.InvalidRequest` naming ones that can.

## Transcription

Pass a URL to the recording, or its bytes:

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

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}")
```

```ts
import { readFile } from "node:fs/promises";
import { AI } from "noclick";

let words = await AI.transcribe("https://example.com/calls/2026-09-26.mp3");
console.log(words.language, words.durationS);
console.log(words.text);

words = await AI.transcribe(await readFile("voicemail.m4a"), { language: "en" });
for (const segment of words.segments) {
  console.log(`${segment.startS.toFixed(1).padStart(6)}s  ${segment.text}`);
}
```

MP3, WAV, M4A, MP4, OGG, WebM, AAC, FLAC and AIFF work, up to 2 hours of audio: 25 MB as bytes, 200 MB behind an `https` URL. `language` (an ISO 639-1 code like `en`) skips detection.

It runs on `noclick/transcribe-1`, which takes the whole recording in one call and hears 90-some languages; one with no two-letter code comes back as its ISO 639-3 code (`yue` for Cantonese). Each segment is a sentence, timed from the start of the recording. It costs its provider's price for each minute of audio, `usd_per_minute` in `AI.models`, and the transcript's `cost_usd` is what the call came to.

### Who said what

`speakers=` tells the voices apart, and each segment's `speaker` says whose it is. The whole recording is heard in one call, so each voice keeps its label from start to end.

`True` labels the voices `speaker_1`, `speaker_2` and on, in the order they first speak. A list of names says how many voices there are, and NoClick works out which voice is which from what they say: the rep introduces the company, the customer asks about the price. A voice it can't tell takes the next unused name in the order the voices first speak, so a call the customer opens with "Hello?" still comes out right when the rep then says who they are:

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

```ts
import { AI } from "noclick";

const call = await AI.transcribe("https://example.com/calls/demo.mp3", { speakers: ["rep", "customer"] });
for (const segment of call.segments) {
  console.log(segment.speaker, segment.text);
}
```

A segment is one voice's turn, from when it starts speaking to when another does. Telling voices apart costs nothing more: `usd_per_minute_with_speakers` in `AI.models` is the same price.

### Long recordings

A whole recording usually comes back well within the 90 seconds a request waits: about 10 seconds for a few minutes of audio, 20 for forty minutes. A longer one, or the service at a busy moment, can take more, so unless your code needs the transcript within the call, pass `background=True`: it returns an [operation](https://www.noclick.com/docs/guide/operations.md) at once, whose `wait()` gives the transcript:

```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)
```

```ts
import { AI } from "noclick";

const job = await AI.transcribe("https://example.com/meetings/all-hands.mp3", { speakers: true, background: true });
const meeting = await job.wait();
console.log(meeting.segments.length, meeting.costUsd);
```

A call without `background` that passes 90 seconds raises `noclick.RequestTimeout` naming its operation (`operation_id`): the transcription goes on, is charged when it's done, and its transcript is the operation's result, so waiting on it picks the transcript up:

```python
try:
    call = noclick.AI.transcribe("https://example.com/calls/demo.mp3", speakers=True)
except noclick.RequestTimeout as late:
    call = noclick.Operation.from_id(late.operation_id).wait()
```

```ts
import { AI, Operation, RequestTimeout, type Transcript } from "noclick";

let call: Transcript;
try {
  call = await AI.transcribe("https://example.com/calls/demo.mp3", { speakers: true });
} catch (err) {
  if (!(err instanceof RequestTimeout)) throw err;
  call = await Operation.fromId<Transcript>(String(err.details.operation_id)).wait();
}
```

An account runs up to 10 transcriptions at once; one more raises `noclick.QuotaExceeded`.

## Pick a model

```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)
```

```ts
import { AI } from "noclick";

for (const m of await AI.models({ kind: "chat" })) {
  console.log(m.id, m.contextLength, m.inputUsdPerToken, m.outputUsdPerToken);
}
```

`kind` is `chat`, `embedding`, `image`, `transcription`, `video` or `agent`. Each model carries what it costs you in US dollars, its provider's own price: per token for chat and embedding models, per token of the image an image model makes, `usd_per_minute` of audio for the transcription model (`usd_per_minute_with_speakers`, the same, when it [tells voices apart](https://www.noclick.com/docs/guide/ai.md#who-said-what)), and `usd_per_second` for video models, for the clip a call naming no length or resolution makes (a video model's `frame_images` also say whether it [starts from a picture](https://www.noclick.com/docs/guide/ai.md#start-from-a-picture)). The default of each kind comes first, and `agent` lists your [agents](https://www.noclick.com/docs/guide/ai.md#talk-to-your-agents-from-any-openai-client).

A chat model also says what it takes, as its provider lists it. `parameters` names the request fields it honours (`tools`, `tool_choice`, `reasoning_effort`, `temperature`, ...); one it doesn't list has no effect, so check before relying on `temperature`. `reasoning` is how it reasons, `None` for a model that doesn't: `mandatory` when it always does, the `efforts` `reasoning_effort` takes, and its `default_effort`.

```python
[sonnet] = noclick.AI.models(model="openrouter/anthropic/claude-sonnet-5.5")
print("temperature" in sonnet.parameters, sonnet.reasoning.mandatory)   # False True
always = [m.id for m in noclick.AI.models(kind="chat") if m.reasoning and m.reasoning.mandatory]
```

```ts
import { AI } from "noclick";

const [sonnet] = await AI.models({ model: "openrouter/anthropic/claude-sonnet-5.5" });
console.log(sonnet.parameters?.includes("temperature"), sonnet.reasoning?.mandatory);   // false true
const always = (await AI.models({ kind: "chat" })).filter((m) => m.reasoning?.mandatory).map((m) => m.id);
```

Anthropic's models refuse a forced tool (`tool_choice` `"required"` or naming a function) while they reason, with "`tool_choice: type "tool" and "any" are not supported for this model`". On one of theirs whose reasoning is `mandatory`, only `"auto"` and `"none"` work: let it choose, and ask again when it answers without the call. On one that can stop (`"none"` among its `efforts`), send `reasoning_effort="none"` with the forced tool.

## Use an OpenAI client

`noclick.AI.base_url` is an OpenAI-compatible endpoint. Point any OpenAI client, or a framework built on one, at it with your NoClick key:

```python
import os

from openai import OpenAI

gpt = OpenAI(base_url=noclick.AI.base_url, api_key=os.environ["NOCLICK_API_KEY"])
completion = gpt.chat.completions.create(
    model="openrouter/anthropic/claude-sonnet-4.6",
    messages=[{"role": "user", "content": "Say hello"}],
)
print(completion.choices[0].message.content)
```

```ts
import OpenAI from "openai";
import { AI } from "noclick";

const gpt = new OpenAI({ baseURL: AI.baseUrl, apiKey: process.env.NOCLICK_API_KEY });
const completion = await gpt.chat.completions.create({
  model: "openrouter/anthropic/claude-sonnet-4.6",
  messages: [{ role: "user", content: "Say hello" }],
});
console.log(completion.choices[0].message.content);
```

It serves chat completions (streaming included, with `tools`, `tool_choice`, `response_format`, `max_tokens`, `temperature` and `reasoning_effort` passed to the model), the Responses API (`gpt.responses.create`, with `instructions`, function tools, streaming and `previous_response_id`), embeddings and the model list. Every model answers both APIs the same way. A response is kept for 30 days so `previous_response_id` can continue it, unless you send `store=False`. Each answer also carries `cost_usd`.

To act for a user, send their id in the `NoClick-User` header, or use a user's [session](https://www.noclick.com/docs/guide/sessions.md) token as the key. Without it the account pays and no user's spend cap applies, so build the client's headers with `noclick.AI.headers()`, which gives your key and, inside `as_user`, the user's header:

```python
from openai import OpenAI

with noclick.as_user("user_42"):
    headers = noclick.AI.headers()   # Authorization, and NoClick-User: user_42
gpt = OpenAI(base_url=noclick.AI.base_url, api_key="-", default_headers=headers)
```

```ts
import OpenAI from "openai";
import { AI, asUser } from "noclick";

const headers = await asUser("user_42", () => AI.headers());   // Authorization, and NoClick-User: user_42
const gpt = new OpenAI({ baseURL: AI.baseUrl, apiKey: "-", defaultHeaders: headers });
```

`api_key` is only a placeholder there: the headers carry the key. Errors come in OpenAI's shape, so the client raises its own matching error; NoClick's type (`invalid_request`, `payment_required`, ...) is the error's `code`. Images, videos and transcription are `noclick.AI.image`, `noclick.AI.video` and `noclick.AI.transcribe` only.

## Talk to your agents from any OpenAI client

Every agent you can message is also a model: `agent:support`, or `agent:` and its id. It talks to that agent in the scope you call from (your account, or the user in `NoClick-User` or the session), on whatever harness it runs.

```python
import os

from openai import OpenAI

gpt = OpenAI(base_url=noclick.AI.base_url, api_key=os.environ["NOCLICK_API_KEY"])
answer = gpt.chat.completions.create(
    model="agent:support",
    messages=[{"role": "user", "content": "Where's my refund?"}],
)
print(answer.choices[0].message.content)
conversation = answer.metadata["conversation"]

follow_up = gpt.chat.completions.create(
    model="agent:support",
    messages=[{"role": "user", "content": "And when will it arrive?"}],
    metadata={"conversation": conversation},
)
```

```ts
import OpenAI from "openai";
import { AI } from "noclick";

const gpt = new OpenAI({ baseURL: AI.baseUrl, apiKey: process.env.NOCLICK_API_KEY });
const answer = await gpt.chat.completions.create({
  model: "agent:support",
  messages: [{ role: "user", content: "Where's my refund?" }],
});
console.log(answer.choices[0].message.content);
// NoClick adds `metadata` to the completion; the openai package's types don't list it.
const { conversation } = (answer as unknown as { metadata: { conversation: string } }).metadata;

const followUp = await gpt.chat.completions.create({
  model: "agent:support",
  messages: [{ role: "user", content: "And when will it arrive?" }],
  metadata: { conversation },
});
```

The agent keeps the conversation, so the rule is simple:

- Without `metadata.conversation`, the whole `messages` list is the first turn of a new conversation, and the answer's `metadata.conversation` names it.
- With it, only the messages after the last assistant message are sent: the agent already has everything before.

The Responses API continues one with `previous_response_id`, or `conversation` set to that name. The reply is the assistant message. The agent runs its own tools, so it never answers with `tool_calls` for you to run, and passing `tools` to an agent fails with `noclick.InvalidRequest`; what it called is listed in the answer's `noclick.tool_calls`. A turn costs what the agent's turns always cost, and counts toward its budget.

The same works from `noclick.AI.chat`, which passes the conversation for you:

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

```ts
import { AI } from "noclick";

const reply = await AI.chat("Where's my refund?", { model: "agent:support" });
const followUp = await AI.chat("And when will it arrive?", { model: "agent:support", conversation: reply.conversation ?? undefined });
console.log(followUp.text);
```

Because agents are listed as models (`owned_by: "noclick-agent"`), a chat UI that speaks OpenAI shows them in its model menu. In Open WebUI, add an OpenAI connection with `https://api.noclick.com/v1/ai` as its URL and a key holding the `agents` scope (and `ai`, to list the models too), and each agent appears in the model menu. Such a UI sends the whole chat on every turn, so each turn starts a new conversation carrying the chat so far.

> [!NOTE]
> Invite-only beta. [Request access](mailto:support@noclick.com?subject=Invite-only%20beta%20access) to use it; without access, such a request starts a new conversation, as above.

A chat UI like that will keep one conversation without knowing it. A request with no `metadata.conversation` whose messages end in an assistant message the agent sent in the last 24 hours, in the same scope, continues that message's conversation: only the messages after it are sent, as if the UI had named the conversation. A chat whose last assistant message the agent didn't write, or wrote longer ago, starts a new conversation as before, and the answer's `metadata.conversation` always says which one it was.

## Long turns

A stream never times out: it starts at once and, while the model thinks or the agent works, carries a comment line every 15 seconds so nothing between you and NoClick closes it. An agent's reply arrives in one piece when its turn ends, whatever its harness (a coding harness such as Claude Code answers only once its turn is done).

A request that doesn't stream waits at most 90 seconds, because a request through NoClick's edge must start answering within about 100. Past that it fails with `noclick.RequestTimeout` (HTTP 503, marked so OpenAI clients don't retry it) telling you to stream. A model's call is stopped and not charged; an agent's turn goes on, and its reply lands in the conversation the error names, readable at the operation in `operation_id`. A transcription goes on the same way (see [Long recordings](https://www.noclick.com/docs/guide/ai.md#long-recordings)). `noclick.AI.chat` always streams, so it never hits this limit.

## Billing and limits

Each call is charged in US dollars at the model's price (its provider's own) and shows as AI on the [Usage page](https://www.noclick.com/dashboard/developers/usage). A call inside `as_user` counts toward that user's [spend cap](https://www.noclick.com/docs/guide/spend.md#cap-it). A model call takes a key with the `ai` scope; an agent model takes the `agents` scope, as messaging an agent always does. In a deployed [app](https://www.noclick.com/docs/guide/apps.md#ai-and-agents-in-the-app), `noclick.Project.current().ai` is this API acting as the app, billed to it and held to its budget.

- `noclick.PaymentRequired`: your account can't pay for the call; its `offers` are links a person opens to pay (see [Errors](https://www.noclick.com/docs/guide/errors.md#money-refusals-carry-their-way-past)).
- `noclick.PlanRequired`: your plan caps it; its `offers` are the plans that don't.
- `noclick.SpendCapExceeded`: the key's or the user's monthly cap is used up.
- `noclick.InvalidRequest`: an unknown model, a model of the wrong kind (an image model to `chat`), a request too long for the model's `context_length`, or `tools` for an agent.
- `noclick.RateLimited`: too many calls at once, or the model's provider is busy; the client retries with backoff before raising it.
- `noclick.UpstreamError`: the model's provider failed; retrying in a moment usually works.
- `noclick.RequestTimeout`: a call that doesn't stream ran past 90 seconds; see [Long turns](https://www.noclick.com/docs/guide/ai.md#long-turns).

The [Python reference](https://www.noclick.com/docs/reference/python/AI.md#AI) has every argument of [`chat`](https://www.noclick.com/docs/reference/python/AI.md#AI.chat), [`embed`](https://www.noclick.com/docs/reference/python/AI.md#AI.embed), [`image`](https://www.noclick.com/docs/reference/python/AI.md#AI.image), [`video`](https://www.noclick.com/docs/reference/python/AI.md#AI.video), [`transcribe`](https://www.noclick.com/docs/reference/python/AI.md#AI.transcribe) and [`models`](https://www.noclick.com/docs/reference/python/AI.md#AI.models).
