---
title: "Embeddings"
description: "Create embeddings with Workers AI models through Laravel AI."
---

> Documentation Index
> Fetch the complete documentation index at: https://laravel-cf-workersai-docs.mdick85.workers.dev/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# Embeddings

Call the `Embeddings` class from Laravel AI:

```php
use Laravel\Ai\Embeddings;

$response = Embeddings::for(['hello', 'world'])
    ->generate(provider: 'workers-ai', model: '@cf/baai/bge-base-en-v1.5');

$response->embeddings; // one vector per input

$response->tokens;                // laravel/ai 0.9 to 0.11: total tokens
$response->usage->inputTokens;    // laravel/ai 1.x: total tokens
```

With no `model:`, the package uses `@cf/baai/bge-large-en-v1.5`. Change the default with `models.embeddings.default`.

## Pass extra request fields

To add request fields, call `withProviderOptions()`:

```php
Embeddings::for(['hello'])
    ->withProviderOptions(['encoding_format' => 'base64'])
    ->generate(provider: 'workers-ai');
```

Before `laravel/ai` 0.9, the method was `providerOptions()`.

The package owns `model` and `input`. It removes these two keys from your options.

## Dimensions

The config key `models.embeddings.dimensions` defaults to `1024`. The package reports this value to Laravel AI but does not send it to Cloudflare. The model sets the real vector size. When you change the model, set `dimensions` to the new size. Otherwise a vector column sized from this value will not match your vectors.

## Gateway note

Embeddings on the gateway provider path `workers-ai/v1` returned `401` on an authenticated gateway in tests on 2026-09-09, and 200 with `gateway_token` on 2026-11-05. The default `/compat` path does not. Remove `gateway_path` to use `/compat`. See [Routes](/docs/concepts/routes/).

Source: https://laravel-cf-workersai-docs.mdick85.workers.dev/docs/guides/embeddings/index.mdx
