You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Commit 9a4855f
Browse filesBrowse the repository at this point in the historyBrowse files
Copy file name to clipboardExpand all lines: docs/guide/ai.md
+8-8Lines changed: 8 additions & 8 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -4,7 +4,7 @@ outline: deep
4
4
5
5
# AI
6
6
7
-
Void provides a typed AI client powered by Cloudflare's [AI Gateway](https://developers.cloudflare.com/ai-gateway/), supporting both [Workers AI](https://developers.cloudflare.com/workers-ai/) models and third-party providers (OpenAI, Anthropic, Google, etc.) via bring-your-own-key. Import `ai` from `void/ai` and run inference models directly from your route handlers — all usage is metered via Void.
7
+
Void provides a typed AI client powered by Cloudflare's [AI Gateway](https://developers.cloudflare.com/ai-gateway/). It supports both [Workers AI](https://developers.cloudflare.com/workers-ai/) models and third-party providers such as OpenAI, Anthropic, and Google through bring-your-own-key credentials. Import `ai` from `void/ai` and run inference directly from your route handlers. Usage is metered through Void.
You can use any model available on [Workers AI](https://developers.cloudflare.com/workers-ai/models/) — text generation, image classification, embeddings, translation, and more.
32
+
You can use any model available on [Workers AI](https://developers.cloudflare.com/workers-ai/models/), including text generation, image classification, embeddings, translation, and more.
33
33
34
34
## Streaming
35
35
36
-
Use `ai.stream()` to get a streaming response with SSE headers — ready to return directly from a route handler:
36
+
Use `ai.stream()` to get a streaming response with SSE headers that you can return directly from a route handler:
AI requires Void credentials for local development. Run `void auth login` and `void project link` (or follow the interactive setup during `vite dev`) to connect your project.
75
75
76
-
Once linked, credentials are injected automatically as worker bindings — no manual configuration needed. All inference traffic routes through the Void AI proxy over HTTPS, so usage is tracked and metered the same way as in production.
76
+
Once linked, credentials are injected automatically as worker bindings. You do not need to configure them by hand. All inference traffic goes through the Void AI proxy over HTTPS, so usage is tracked and metered the same way it is in production.
77
77
78
78
## Usage Limits
79
79
80
-
Workers AI usage is metered in [**neurons**](https://developers.cloudflare.com/workers-ai/platform/pricing/) — Cloudflare's unit for inference cost. Usage resets at the start of each billing cycle.
80
+
Workers AI usage is metered in [**neurons**](https://developers.cloudflare.com/workers-ai/platform/pricing/), which is Cloudflare's unit for inference cost. Usage resets at the start of each billing cycle.
@@ -89,7 +89,7 @@ On the **free tier**, AI requests return a `429` error once the limit is reached
89
89
90
90
## Third-Party Providers (BYOK)
91
91
92
-
You can use models from OpenAI, Anthropic, Google, and other providers by passing a `provider/model` identifier. Bring your own API key — add it as a project secret, and Void handles the rest. Third-party inference is billed directly by the provider — Void does not mark up API calls. All requests still route through AI Gateway for usage tracking on the dashboard.
92
+
You can use models from OpenAI, Anthropic, Google, and other providers by passing a `provider/model` identifier. Bring your own API key, add it as a project secret, and Void handles the rest. Third-party inference is billed directly by the provider, and Void does not mark up API calls. Requests still route through AI Gateway so usage shows up on the dashboard.
The same `ai.run()` and `ai.stream()` methods work for both Workers AI and third-party models. The framework detects the provider from the model string and routes the request through [AI Gateway](https://developers.cloudflare.com/ai-gateway/) automatically.
113
113
114
-
The options follow each provider's conventions — all third-party providers use the OpenAI-compatible chat completions format (`messages`, `max_tokens`, `temperature`, etc.). TypeScript narrows the input and return types based on the model string: Workers AI models get per-model typed inputs from `@cloudflare/workers-types`, while third-party models (`"provider/model"`) get `ChatCompletionInputs` and `ChatCompletionResponse`.
114
+
The options follow each provider's conventions. All third-party providers use the OpenAI-compatible chat completions format, including `messages`, `max_tokens`, and `temperature`. TypeScript narrows the input and return types based on the model string: Workers AI models get per-model typed inputs from `@cloudflare/workers-types`, while third-party models such as `"provider/model"` get `ChatCompletionInputs` and `ChatCompletionResponse`.
115
115
116
116
### Provider Key Convention
117
117
@@ -158,7 +158,7 @@ If the key is missing at runtime, `ai.run()` throws a descriptive error telling
158
158
159
159
### Streaming with Third-Party Models
160
160
161
-
`ai.stream()` works the same way — the response is always SSE regardless of provider:
161
+
`ai.stream()` works the same way. The response is always SSE regardless of provider:
3.**Static sites**— SPAs, static sites like [VitePress](https://vitepress.dev/), or any directory of static files
9
+
1.**Void apps:** Vite apps powered by Void's framework layer, including [API routes](./server-routing.md), [pages mode](./pages-routing/overview.md), [auth](./auth.md), [crons](./jobs.md), and [queues](./queues.md)
3.**Static sites:** SPAs, sites built with tools like [VitePress](https://vitepress.dev/), or any directory of static files
12
12
13
13
The type is auto-detected from your project structure, or you can set it explicitly in [`void.json`](../reference/config.md).
14
14
15
15
## Void Apps
16
16
17
-
A Vite app powered by Void's framework layer. In this mode, **Void is both the framework and the platform** — an opinionated setup that unlocks DX perks unique to Void, while staying frontend-framework-agnostic. You can use it with React, Vue, Svelte, Solid, or any frontend that works with Vite.
17
+
A Vite app powered by Void's framework layer. In this mode, **Void is both the framework and the platform**. It is opinionated in the backend and deployment story, while still staying frontend-framework-agnostic. You can use it with React, Vue, Svelte, Solid, or any frontend that works with Vite.
18
18
19
-
All Void features that involve backend logic — [server routing](./server-routing.md), [pages mode](./pages-routing/overview.md), [authentication](./auth.md), [typed fetch](./typed-fetch.md), [cron jobs](./jobs.md), [queues](./queues.md) — are available in this mode.
19
+
All Void features that involve backend logic are available in this mode, including [server routing](./server-routing.md), [pages mode](./pages-routing/overview.md), [authentication](./auth.md), [typed fetch](./typed-fetch.md), [cron jobs](./jobs.md), and [queues](./queues.md).
20
20
21
21
A Void app can be **API-only** (just `routes/`), a **SPA + API** (frontend in `src/` with API routes), or **full-stack with pages mode** (server-rendered pages in `pages/` with co-located data loading):
22
22
23
23
<VoidAppFileTreeannotations />
24
24
25
25
Your worker handles API routes, page rendering, and (optionally) [custom SSR](./ssr.md). Static assets are served from the edge via per-worker assets. Cloudflare bindings (D1, KV, R2) are [inferred from your source code](../reference/resource-inference.md) and provisioned automatically.
26
26
27
-
Void apps can also be configured with [`output: 'static'`](./ssg.md) to pre-render all pages at build time, producing a fully static site that can be deployed anywhere — no Cloudflare Workers required.
27
+
Void apps can also use [`output: 'static'`](./ssg.md) to pre-render all pages at build time. That gives you a fully static site that can be deployed anywhere, with no Cloudflare Worker required.
28
28
29
29
**Deploy:**`void deploy` builds via Vite, infers bindings, provisions D1/KV/R2 resources, applies migrations, uploads assets and worker, and makes the site live at `{slug}.void.app`. See [Deployment](./deployment.md) for details.
30
30
@@ -39,7 +39,7 @@ Void apps can also be configured with [`output: 'static'`](./ssg.md) to pre-rend
39
39
40
40
## Meta Frameworks
41
41
42
-
Void supports deploying Vite-based meta-framework apps via`void deploy`. The framework owns routing and SSR — Void handles [binding inference](../reference/resource-inference.md), [typed DB queries](./database.md), migrations, and deployment.
42
+
Void supports deploying Vite-based meta-framework apps with`void deploy`. The framework owns routing and SSR. Void handles [binding inference](../reference/resource-inference.md), [typed DB queries](./database.md), migrations, and deployment.
43
43
44
44
| Framework | Detected from package | Setup guide |
@@ -51,13 +51,13 @@ Void supports deploying Vite-based meta-framework apps via `void deploy`. The fr
51
51
52
52
Add `voidPlugin()` to the framework's Vite config to get binding inference, typed DB generation, migration management, auth, cron jobs, queues, and caching. See the [Meta Frameworks Integration](../integrations/frameworks/overview.md) for the full feature matrix, deploy pipeline, and per-framework setup guides.
53
53
54
-
**Deploy:**`void deploy` runs the framework's build, packages the output, and deploys to Void. The framework owns routing and SSR — Void handles resource provisioning, migrations, and edge hosting.
54
+
**Deploy:**`void deploy` runs the framework build, packages the output, and deploys to Void. The framework still owns routing and SSR, while Void handles resource provisioning, migrations, and edge hosting.
55
55
56
56
**Detected when** any of the above packages is in your dependencies.
57
57
58
58
## Pre-built Static Sites
59
59
60
-
Any project that produces static files — SPAs, static sites, or plain directories. Assets are served directly from the edge. A minimal passthrough worker is generated automatically — no user code is needed.
60
+
Any project that produces static files, whether that is an SPA, a static site, or a plain directory. Assets are served directly from the edge, and a minimal passthrough worker is generated automatically. You do not need to write worker code yourself.
61
61
62
62
**SPAs** (client-side single-page apps) fall back all non-file paths to `index.html` with a 200 status, so client-side routing works out of the box. Detected when `vite` is a dependency and no backend files exist.
63
63
@@ -70,7 +70,7 @@ At the edge, the resolution order is:
70
70
3.`404.html` with **status 404** (if the file exists)
71
71
4. Plain 404 response
72
72
73
-
**Deploy:**`void deploy`(or `void deploy --dir <path>`) uploads static files directly — no worker code needed. Assets are served from the edge with automatic caching.
73
+
**Deploy:**`void deploy` or `void deploy --dir <path>` uploads static files directly. Assets are served from the edge with automatic caching.
Copy file name to clipboardExpand all lines: docs/guide/database.md
+13-13Lines changed: 13 additions & 13 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -32,7 +32,7 @@ const dbFileItems = [
32
32
33
33
# Database
34
34
35
-
Void provides a first-class [Drizzle ORM](https://orm.drizzle.team) integration. Define your schema as TypeScript, import a pre-wired Drizzle instance from `void/db`, and start querying — no extra install needed.
35
+
Void provides a first-class [Drizzle ORM](https://orm.drizzle.team) integration. Define your schema in TypeScript, import the pre-wired Drizzle instance from `void/db`, and start querying. You do not need an extra install.
Everything ships with `void` — there is nothing extra to install. You don't have to write this by hand — use`void gen model` or let your coding agent generate it.
89
+
Everything ships with `void`, so there is nothing extra to install. You also do not have to write this by hand. Use`void gen model` or let your coding agent generate it.
90
90
91
91
You can also split your schema across multiple files under `db/schema/` and re-export from a barrel file:
92
92
@@ -112,7 +112,7 @@ import { users } from "@schema";
112
112
```
113
113
114
114
::: info What is `@schema`?
115
-
`@schema` is a Vite path alias that the Void plugin configures automatically to point to your `db/schema.ts` file (or `db/schema/`directory). You don't need to set it up — just use it to import your table definitions.
115
+
`@schema` is a Vite path alias that the Void plugin configures automatically. It points to your `db/schema.ts` file, or `db/schema/`if you split tables across files. You can just use it to import table definitions.
`createInsertSchema` generates a validator that matches `$inferInsert` — columns with defaults or auto-increments become optional, `NOT NULL` columns are required. The optional second argument refines individual columns — either via a callback that receives the auto-generated schema, or by passing a type directly to override the field.
304
+
`createInsertSchema` generates a validator that matches `$inferInsert`. Columns with defaults or auto-increments become optional, while `NOT NULL` columns stay required. The optional second argument lets you refine individual columns, either with a callback that receives the generated schema or by passing a type directly to override a field.
305
305
306
306
Use the derived schema in your route handlers with [`withValidator()`](./server-routing.md#validation):
307
307
@@ -321,11 +321,11 @@ export const POST = defineHandler.withValidator({
|`createSelectSchema`| Matches the shape of selected rows |
328
+
|`createUpdateSchema`| Like insert but all fields are optional (partial update) |
329
329
330
330
Void already bundles the Drizzle adapters. Install the validator library itself if you use its direct APIs in your schema file:
331
331
@@ -356,17 +356,17 @@ See the [CLI reference](../reference/cli.md#database) for details.
356
356
357
357
## Scaffolding
358
358
359
-
The `void gen model` command scaffolds a Drizzle table definition and updates your barrel export. It generates dialect-appropriate code — `sqliteTable` for D1, `pgTable` for PostgreSQL:
359
+
The `void gen model` command scaffolds a Drizzle table definition and updates your barrel export. It generates dialect-appropriate code: `sqliteTable` for D1 and `pgTable` for PostgreSQL.
360
360
361
361
```bash
362
362
void gen model post title:string body:text published:boolean
363
363
```
364
364
365
365
This creates:
366
366
367
-
1.`db/schema/post.ts` — a Drizzle table definition with `id`, `createdAt`, `updatedAt`, and your columns
367
+
1.`db/schema/post.ts`: a Drizzle table definition with `id`, `createdAt`, `updatedAt`, and your columns
368
368
2. Updates `db/schema.ts` with `export * from "./schema/post"`
369
-
3.`routes/api/posts/index.ts` — GET (list) + POST (insert with validation)
370
-
4.`routes/api/posts/[id].ts` — GET by id with 404 handling
369
+
3.`routes/api/posts/index.ts`: `GET` for list and `POST` for insert with validation
370
+
4.`routes/api/posts/[id].ts`: `GET` by id with `404` handling
371
371
372
372
See the [CLI reference](../reference/cli.md#code-generation) for the full list of generators.
0 commit comments