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

# AI models

> Chat, streaming, embeddings and image generation - no API key to manage.

Model ids are `provider/model` strings. Spend is billed to the backend.

```ts theme={"dark"}
const completion = await backend.ai.chat.completions.create({
  model: "openai/gpt-4o-mini",
  messages: [{ role: "user", content: "Summarize this..." }],
});
console.log(completion.choices[0].message.content);
```

## Streaming

```ts theme={"dark"}
const stream = await backend.ai.chat.completions.create({
  model: "openai/gpt-4o-mini",
  messages,
  stream: true,
});
for await (const chunk of stream) {
  process.stdout.write(chunk.choices[0]?.delta?.content ?? "");
}
```

## Embeddings

```ts theme={"dark"}
const res = await backend.ai.embeddings.create({
  model: "openai/text-embedding-3-small",
  input: "hello world",
});
// res.data[0].embedding → number[]
```

Pairs with pgvector - enable it with a
[SQL migration](/cli/reference#db-migrate).

## Images

```ts theme={"dark"}
const img = await backend.ai.images.generate({
  model: "google/gemini-2.5-flash-image",
  prompt: "A sunset over mountains",
});
// img.data[0].b64_json → base64 PNG
```

<Warning>
  AI calls work with the publishable key, so anyone holding it can drive spend.
  Keep expensive or sensitive AI calls in a
  [serverless function](/sdk/functions).
</Warning>
