@xano/developer-mcp 2.3.0-beta.6 → 2.3.0-beta.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (46) hide show
  1. package/README.md +4 -16
  2. package/dist/cli_docs/index.js +0 -4
  3. package/dist/cli_docs/topics/function.js +0 -2
  4. package/dist/cli_docs/topics/knowledge.js +1 -2
  5. package/dist/cli_docs/topics/workspace.js +23 -12
  6. package/dist/meta_api_docs/index.js +0 -2
  7. package/dist/meta_api_docs/topics/api.js +6 -6
  8. package/dist/meta_api_docs/topics/apigroup.js +2 -2
  9. package/dist/meta_api_docs/topics/authentication.js +1 -1
  10. package/dist/meta_api_docs/topics/history.js +39 -10
  11. package/dist/meta_api_docs/topics/mcp_server.js +6 -6
  12. package/dist/meta_api_docs/topics/middleware.js +1 -1
  13. package/dist/meta_api_docs/topics/table.js +2 -2
  14. package/dist/meta_api_docs/topics/workspace.js +1 -1
  15. package/dist/tools/validate_xanoscript.js +1 -5
  16. package/dist/xanoscript.js +0 -1
  17. package/dist/xanoscript_docs/README.md +25 -9
  18. package/dist/xanoscript_docs/agents.md +3 -0
  19. package/dist/xanoscript_docs/ai.md +820 -0
  20. package/dist/xanoscript_docs/branch.md +109 -29
  21. package/dist/xanoscript_docs/database.md +7 -5
  22. package/dist/xanoscript_docs/docs_index.json +36 -28
  23. package/dist/xanoscript_docs/essentials.md +53 -19
  24. package/dist/xanoscript_docs/file-uploads.md +4 -4
  25. package/dist/xanoscript_docs/mcp-servers.md +2 -2
  26. package/dist/xanoscript_docs/prompts.md +4 -2
  27. package/dist/xanoscript_docs/realtime-v2.md +4 -2
  28. package/dist/xanoscript_docs/resources.md +3 -1
  29. package/dist/xanoscript_docs/survival.md +1 -5
  30. package/dist/xanoscript_docs/tables.md +58 -0
  31. package/dist/xanoscript_docs/tools.md +1 -1
  32. package/dist/xanoscript_docs/triggers.md +133 -3
  33. package/dist/xanoscript_docs/types.md +14 -1
  34. package/dist/xanoscript_docs/unit-testing.md +29 -2
  35. package/dist/xanoscript_docs/version.json +2 -2
  36. package/dist/xanoscript_docs/workflow-tests.md +18 -0
  37. package/dist/xanoscript_docs/working.md +39 -15
  38. package/package.json +2 -3
  39. package/dist/cli_docs/topics/policy.d.ts +0 -2
  40. package/dist/cli_docs/topics/policy.js +0 -92
  41. package/dist/cli_docs/topics/skills.d.ts +0 -2
  42. package/dist/cli_docs/topics/skills.js +0 -57
  43. package/dist/meta_api_docs/topics/policy.d.ts +0 -3
  44. package/dist/meta_api_docs/topics/policy.js +0 -140
  45. package/dist/xanoscript_docs/policies.md +0 -448
  46. package/dist/xanoscript_docs/policy-templates.md +0 -267
@@ -0,0 +1,820 @@
1
+ ---
2
+ applyTo: "function/**/*.xs, api/**/*.xs, task/*.xs, ai/tool/*.xs"
3
+ ---
4
+
5
+ # AI Statements (Xano AI)
6
+
7
+ One-shot model calls inside any function stack: generate text, images, video, speech and music, transcribe audio, create embeddings and rerank documents.
8
+
9
+ > **TL;DR:** `ai.text.generate`, `ai.image.generate`, `ai.video.generate`, `ai.speech.generate`, `ai.speech.transcribe`, `ai.embedding.create`, `ai.rerank` and `ai.music.generate`. Each takes a `model` (a catalog model name), its inputs, and ends with `as $var`. They bill **Xano AI credits only**: there is no provider, `api_key` or BYO-model field. Media comes back as a **file resource**, which is not stored until you store it: set `save_to_files = "public"` (or `"private"`) and the media key (`image`/`video`/`audio`) holds the stored file instead, or pass the file resource to `storage.create_image` / `storage.create_video` / `storage.create_audio`. An optional `location` (`"us"`, `"global"` or `"eu"`) picks where the model runs; blank uses the workspace's.
10
+
11
+ ## Choosing a Statement
12
+
13
+ ```
14
+ Need a model to...
15
+ ├── One-shot call (one request, one answer)? → ai.*.generate and friends
16
+ │ ├── Write or classify text, answer a question, return JSON? → ai.text.generate
17
+ │ ├── Create or edit an image? → ai.image.generate
18
+ │ ├── Create a short video clip? → ai.video.generate
19
+ │ ├── Read text aloud (text to speech)? → ai.speech.generate
20
+ │ ├── Turn audio into text (speech to text)? → ai.speech.transcribe
21
+ │ ├── Create instrumental music or a song? → ai.music.generate
22
+ │ ├── Turn text or media into vectors for search? → ai.embedding.create
23
+ │ └── Re-order search results by relevance to a query? → ai.rerank
24
+ └── Tools, multi-step reasoning, or a conversation loop? → ai.agent.run (see `agents`)
25
+ ```
26
+
27
+ **Rule of thumb:** need a one-shot model call → `ai.*.generate`; need tools or multiple steps → `ai.agent.run`.
28
+
29
+ ## Quick Reference
30
+
31
+ | Statement | Purpose | Required keys | Returns (`as $result`) |
32
+ |-----------|---------|---------------|------------------------|
33
+ | `ai.text.generate` | Text or JSON generation | `model`, `prompt` (or `messages`) | `{text, json, model, finish_reason, usage}` |
34
+ | `ai.image.generate` | Create or edit an image | `model`, `prompt` | `{image, text, model, usage}` |
35
+ | `ai.video.generate` | Create a video clip | `model`, `prompt` | `{video, model, duration}` |
36
+ | `ai.speech.generate` | Text to speech | `model`, `text` | `{audio, model, usage}` |
37
+ | `ai.speech.transcribe` | Speech to text | `model`, `audio` | `{text, model, usage}` |
38
+ | `ai.embedding.create` | Embedding vectors | `model`, `input` | `{embeddings, model, usage}` |
39
+ | `ai.rerank` | Rank documents against a query | `model`, `query`, `documents` | `{results, model}` |
40
+ | `ai.music.generate` | Music clip or song | `model`, `prompt` | `{audio, lyrics, description, model}` |
41
+
42
+ Every statement also accepts `description`, `disabled` and `mock`, like any other statement. `usage` is `{input_tokens, output_tokens}` when the model reports tokens, else `{}`.
43
+
44
+ `image`, `video` and `audio` in a result are **temporary file resources**: nothing is saved unless you ask. See **Storing Media** below.
45
+
46
+ Inputs that take media (`files`, `images`, `image`, `last_image`, `audio`, and file items in `input`) take a file resource: a `file?` input, the media output of another `ai.*` statement, or the result of `storage.create_file_resource`.
47
+
48
+ ---
49
+
50
+ ## Storing Media: `save_to_files` or a From File Statement
51
+
52
+ `ai.image.generate`, `ai.video.generate`, `ai.speech.generate` and `ai.music.generate` take an optional `save_to_files` key:
53
+
54
+ | `save_to_files` | Effect | The media key (`image`/`video`/`audio`) holds |
55
+ |-----------------|--------|-----------------------------------------------|
56
+ | `""` (default) | off: nothing is stored | the temporary file resource |
57
+ | `"public"` | saves the result to Files with public access | the stored file object (with `url`) |
58
+ | `"private"` | saves the result to Files with private access | the stored file object |
59
+
60
+ There is no separate key for the stored file: with `save_to_files` set, the media key itself is the stored file. The other keys (`model`, `usage`, ...) are unchanged.
61
+
62
+ `save_to_files` is a **shortcut**. It saves exactly as the matching From File statement does, and the media key holds exactly what that statement returns (same vault path, same file object, same URL):
63
+
64
+ | Statement | Same as adding |
65
+ |-----------|----------------|
66
+ | `ai.image.generate` | `storage.create_image` (Create Image From File) |
67
+ | `ai.video.generate` | `storage.create_video` (Create Video From File) |
68
+ | `ai.speech.generate` | `storage.create_audio` (Create Audio From File) |
69
+ | `ai.music.generate` | `storage.create_audio` (Create Audio From File) |
70
+
71
+ Put the stored file (the media key with `save_to_files` set, or the From File statement's result) into a file column, never the raw file resource: a file resource in a file column saves `null`.
72
+
73
+ Both ways, storing a generated image in a table:
74
+
75
+ ```xs
76
+ function "store_fox_shortcut" {
77
+ input {
78
+ }
79
+ stack {
80
+ // 1. Shortcut: with save_to_files set, $fox.image is the stored file
81
+ ai.image.generate {
82
+ model = "gemini-3.1-flash-image"
83
+ prompt = "A red fox, watercolor"
84
+ save_to_files = "public"
85
+ } as $fox
86
+
87
+ db.add "gallery" {
88
+ data = {
89
+ image: $fox.image
90
+ }
91
+ } as $row
92
+ }
93
+ response = $row
94
+ }
95
+ ```
96
+
97
+ ```xs
98
+ function "store_fox_explicit" {
99
+ input {
100
+ }
101
+ stack {
102
+ // 2. Explicit: the From File statement (storage.create_image) on the file resource
103
+ ai.image.generate {
104
+ model = "gemini-3.1-flash-image"
105
+ prompt = "A red fox, watercolor"
106
+ } as $fox
107
+
108
+ storage.create_image {
109
+ value = $fox.image
110
+ access = "public"
111
+ filename = "fox.png"
112
+ } as $stored
113
+
114
+ db.add "gallery" {
115
+ data = {
116
+ image: $stored
117
+ }
118
+ } as $row
119
+ }
120
+ response = $row
121
+ }
122
+ ```
123
+
124
+ Use the explicit statement when you need your own `filename`; the shortcut uses the statement's default name (for example `image.png` or `speech.wav`). To store in your own bucket instead, upload the file resource yourself (see `integrations/cloud-storage`).
125
+
126
+ ---
127
+
128
+ ## Billing: Xano AI Credits Only
129
+
130
+ - These statements call Xano-hosted models through the Xano AI gateway and charge the workspace owner's **Xano AI credits**.
131
+ - There is **no** `api_key`, `provider` or custom-model field. Writing one is a validation error. To use your own key or provider, call it with `api.request` (see `integrations/external-apis`) or configure an agent with that provider (see `agents`).
132
+ - When credits run out, the statement fails with code **`credits_exhausted`** ("Xano AI credits are exhausted. The account owner can buy more credits on the billing page"). An account on hold fails with **`account_on_hold`**. Wrap the call in `try_catch` when the endpoint must still answer without AI.
133
+ - A model that is not in the statement's catalog is refused with an error that lists the allowed models. Per-model options are checked too (for example `image_size = "4K"` on `gemini-3.1-flash-lite-image` is refused).
134
+
135
+ ```xs
136
+ function "summarize_or_skip" {
137
+ input {
138
+ text body
139
+ }
140
+ stack {
141
+ var $summary {
142
+ value = null
143
+ }
144
+
145
+ try_catch {
146
+ try {
147
+ ai.text.generate {
148
+ model = "gemini-3.8-flash"
149
+ prompt = "Summarize in two sentences:\n" ~ $input.body
150
+ } as $result
151
+
152
+ var.update $summary {
153
+ value = $result.text
154
+ }
155
+ }
156
+ catch {
157
+ debug.log {
158
+ value = "Xano AI unavailable (credits_exhausted or account_on_hold); returning no summary"
159
+ }
160
+ }
161
+ }
162
+ }
163
+ response = $summary
164
+ }
165
+ ```
166
+
167
+ ---
168
+
169
+ ## Location: `location`
170
+
171
+ Every `ai.*` statement takes an optional `location`: where Xano AI runs the model.
172
+
173
+ | `location` | Effect |
174
+ | --- | --- |
175
+ | `""` (default) | The workspace's Xano AI location (Workspace Settings → AI Preferences), else Xano's default |
176
+ | `"us"` | Processing stays in the US |
177
+ | `"eu"` | Processing stays in the EU |
178
+ | `"global"` | Runs where Xano's hub runs it (Google's global endpoint; `us-central1` for video and `lyria-002`) |
179
+
180
+ - `"us"` and `"eu"` are offered only for the models that run there: the Gemini text models, the Claude models, `gemini-3.1-flash-image` and `gemini-embedding-2`. Any other model at `"us"` or `"eu"` is an error. The request is never moved to another location.
181
+ - Any other value (such as `"europe-west4"`) is a validation error.
182
+ - A Xano AI agent takes the same `location` in its `llm` block.
183
+
184
+ ```xs
185
+ function "summarize_in_eu" {
186
+ input {
187
+ text body
188
+ }
189
+ stack {
190
+ ai.text.generate {
191
+ model = "gemini-3.8-flash"
192
+ prompt = $input.body
193
+ location = "eu"
194
+ } as $summary
195
+ }
196
+ response = $summary.text
197
+ }
198
+ ```
199
+
200
+ ---
201
+
202
+ ## Models
203
+
204
+ `model` is plain text, so a new catalog model needs no syntax change. The **suggested** model is the default the builder picks; use it unless you have a reason not to. Tiers are guidance: `best` (highest quality), `balanced`, `fast` (cheapest, lowest latency).
205
+
206
+ | Statement | Model | Tier | Stage | Notes |
207
+ |-----------|-------|------|-------|-------|
208
+ | `ai.text.generate` | `gemini-3.8-flash` | balanced | GA | **Suggested** |
209
+ | | `gemini-4-argon` | best | GA | |
210
+ | | `gemini-3.5-flash-lite` | fast | GA | |
211
+ | | `claude-fable-5-1` | best | GA | Anthropic on Vertex |
212
+ | | `claude-opus-5-5` | best | GA | Anthropic on Vertex |
213
+ | | `claude-sonnet-5-5` | balanced | GA | Anthropic on Vertex |
214
+ | | `claude-haiku-5-5` | fast | GA | Anthropic on Vertex |
215
+ | `ai.image.generate` | `gemini-3.1-flash-image` | balanced | GA | **Suggested** (Nano Banana 2); sizes 1K/2K/4K |
216
+ | | `gemini-nano-banana-2.1` | balanced | GA | Nano Banana 2.1; sizes 1K/2K/4K |
217
+ | | `gemini-3-pro-image` | best | GA | Nano Banana Pro; sizes 1K/2K/4K |
218
+ | | `gemini-3.1-flash-lite-image` | fast | GA | size 1K only |
219
+ | `ai.video.generate` | `veo-3.1-fast-generate-001` | balanced | GA | **Suggested**; 720p, 1080p, 4k |
220
+ | | `veo-3.1-generate-001` | best | GA | 720p, 1080p, 4k |
221
+ | | `veo-3.1-lite-generate-001` | fast | Preview | 720p, 1080p |
222
+ | `ai.speech.generate` | `gemini-3.8-flash-tts` | balanced | GA | **Suggested** |
223
+ | | `gemini-3.8-flash-lite-tts` | fast | GA | |
224
+ | `ai.speech.transcribe` | `gemini-3.5-transcribe` | default | GA | **Suggested** |
225
+ | `ai.embedding.create` | `gemini-embedding-2` | default | GA | **Suggested**; text, image, audio, video |
226
+ | | `gemini-embedding-001` | text only | GA | text only |
227
+ | `ai.rerank` | `semantic-ranker-default-005` | default | GA | **Suggested** |
228
+ | `ai.music.generate` | `lyria-002` | default | GA | **Suggested**; 32.8 s instrumental WAV |
229
+ | | `lyria-3-clip-preview` | fast | Preview | 30 s clip, MP3; returns `lyrics`/`description` |
230
+ | | `lyria-3-pro-preview` | best | Preview | full song up to 184 s, vocals, MP3; returns `lyrics`/`description` |
231
+
232
+ ---
233
+
234
+ ## ai.text.generate
235
+
236
+ Generate text, or JSON that matches a schema, from a prompt, prior messages and optional files.
237
+
238
+ | Key | Default | Notes |
239
+ |-----|---------|-------|
240
+ | `model` | `"gemini-3.8-flash"` | a text model from the table |
241
+ | `prompt` | — | text; required unless `messages` is set |
242
+ | `system` | `""` | system instructions |
243
+ | `messages` | `[]` | prior turns: `[{role: "user" \| "assistant", content: "..."}]` |
244
+ | `files` | `[]` | file resources sent with the prompt: image, PDF, audio and video on Gemini models; image and PDF on Claude |
245
+ | `temperature` | `null` | decimal `0`..`2`; `null` uses the model default |
246
+ | `max_tokens` | `null` | int; `null` uses the model default |
247
+ | `response_format` | `"text"` | `"text"` or `"json"` |
248
+ | `json_schema` | `null` | a JSON Schema object; use with `response_format = "json"` |
249
+
250
+ **Output:** `{text, json, model, finish_reason, usage}`. `json` is the parsed object when `response_format` is `"json"`, else `null`.
251
+
252
+ ```xs
253
+ function "extract_invoice_fields" {
254
+ input {
255
+ file? invoice
256
+ }
257
+ stack {
258
+ ai.text.generate {
259
+ model = "gemini-3.8-flash"
260
+ system = "You extract structured data from invoices. Use null for missing values."
261
+ prompt = "Extract the vendor, invoice number, total and due date."
262
+ files = [$input.invoice]
263
+ temperature = 0
264
+ response_format = "json"
265
+ json_schema = {
266
+ type: "object"
267
+ properties: {
268
+ vendor: {type: "string"}
269
+ invoice_number: {type: "string"}
270
+ total: {type: "number"}
271
+ due_date: {type: "string", format: "date"}
272
+ }
273
+ required: ["vendor", "total"]
274
+ }
275
+ } as $result
276
+ }
277
+ response = $result.json
278
+ }
279
+ ```
280
+
281
+ Continue a conversation with `messages` (the new `prompt` is the latest user turn):
282
+
283
+ ```xs
284
+ function "chat_reply" {
285
+ input {
286
+ json history
287
+ text question
288
+ }
289
+ stack {
290
+ ai.text.generate {
291
+ model = "claude-haiku-5-5"
292
+ system = "You are a concise support assistant for Acme."
293
+ messages = $input.history
294
+ prompt = $input.question
295
+ max_tokens = 400
296
+ } as $reply
297
+ }
298
+ response = $reply.text
299
+ }
300
+ ```
301
+
302
+ ---
303
+
304
+ ## ai.image.generate
305
+
306
+ Create an image from a prompt, or edit one: passing any image in `images` makes it an edit.
307
+
308
+ | Key | Default | Notes |
309
+ |-----|---------|-------|
310
+ | `model` | `"gemini-3.1-flash-image"` | an image model from the table |
311
+ | `prompt` | — | required |
312
+ | `images` | `[]` | file resources; any image makes this an edit |
313
+ | `aspect_ratio` | `"1:1"` | `1:1` `2:3` `3:2` `3:4` `4:3` `4:5` `5:4` `9:16` `16:9` `21:9` |
314
+ | `image_size` | `"1K"` | `1K`, `2K` or `4K`, as the model allows |
315
+ | `save_to_files` | `""` | `""` (off), `"public"` or `"private"`; shortcut for `storage.create_image` |
316
+
317
+ **Output:** `{image, text, model, usage}`. `image` is the stored file object when `save_to_files` is set, else a temporary file resource; `text` is any text the model returned, else `""`.
318
+
319
+ Generate an image and store it with the shortcut:
320
+
321
+ ```xs
322
+ function "create_product_hero" {
323
+ input {
324
+ text product_name
325
+ }
326
+ stack {
327
+ ai.image.generate {
328
+ model = "gemini-3.1-flash-image"
329
+ prompt = "Studio product photo of " ~ $input.product_name ~ " on a white background, soft shadows"
330
+ aspect_ratio = "16:9"
331
+ image_size = "2K"
332
+ save_to_files = "public"
333
+ } as $generated
334
+
335
+ db.add "product_image" {
336
+ data = {
337
+ product_name: $input.product_name
338
+ image: $generated.image
339
+ }
340
+ } as $row
341
+ }
342
+ response = $row
343
+ }
344
+ ```
345
+
346
+ Edit an uploaded image and store it with the explicit From File statement (`storage.create_image`), here to set the filename:
347
+
348
+ ```xs
349
+ function "remove_background" {
350
+ input {
351
+ file? photo
352
+ }
353
+ stack {
354
+ ai.image.generate {
355
+ model = "gemini-3-pro-image"
356
+ prompt = "Remove the background and replace it with plain white. Keep the subject unchanged."
357
+ images = [$input.photo]
358
+ } as $edited
359
+
360
+ storage.create_image {
361
+ value = $edited.image
362
+ access = "private"
363
+ filename = "edited.png"
364
+ } as $stored
365
+ }
366
+ response = $stored
367
+ }
368
+ ```
369
+
370
+ ---
371
+
372
+ ## ai.video.generate
373
+
374
+ Create a short video clip, optionally from a first and last frame. The statement waits for the result up to `timeout`.
375
+
376
+ | Key | Default | Notes |
377
+ |-----|---------|-------|
378
+ | `model` | `"veo-3.1-fast-generate-001"` | a video model from the table |
379
+ | `prompt` | — | required |
380
+ | `negative_prompt` | `""` | what to avoid |
381
+ | `image` | `null` | file resource; the first frame |
382
+ | `last_image` | `null` | file resource; the last frame |
383
+ | `aspect_ratio` | `"16:9"` | `16:9` or `9:16` |
384
+ | `resolution` | `"720p"` | `720p`, `1080p`, or `4k` (not on `veo-3.1-lite-generate-001`) |
385
+ | `duration` | `8` | `4`, `6` or `8` seconds |
386
+ | `generate_audio` | `true` | generate a soundtrack |
387
+ | `timeout` | `300` | seconds to wait for the result |
388
+ | `save_to_files` | `""` | `""` (off), `"public"` or `"private"`; shortcut for `storage.create_video` |
389
+
390
+ **Output:** `{video, model, duration}`. `video` is the stored file object when `save_to_files` is set, else a temporary file resource.
391
+
392
+ Store the clip with the shortcut:
393
+
394
+ ```xs
395
+ function "animate_listing_photo" {
396
+ input {
397
+ file? photo
398
+ }
399
+ stack {
400
+ ai.video.generate {
401
+ model = "veo-3.1-fast-generate-001"
402
+ prompt = "Slow cinematic push-in on the living room, warm afternoon light"
403
+ negative_prompt = "people, text, watermarks"
404
+ image = $input.photo
405
+ aspect_ratio = "9:16"
406
+ resolution = "1080p"
407
+ duration = 6
408
+ generate_audio = false
409
+ timeout = 600
410
+ save_to_files = "public"
411
+ } as $clip
412
+ }
413
+ response = $clip.video
414
+ }
415
+ ```
416
+
417
+ The same with the explicit From File statement:
418
+
419
+ ```xs
420
+ function "animate_listing_photo_explicit" {
421
+ input {
422
+ file? photo
423
+ }
424
+ stack {
425
+ ai.video.generate {
426
+ model = "veo-3.1-fast-generate-001"
427
+ prompt = "Slow cinematic push-in on the living room, warm afternoon light"
428
+ image = $input.photo
429
+ } as $clip
430
+
431
+ storage.create_video {
432
+ value = $clip.video
433
+ access = "public"
434
+ filename = "listing.mp4"
435
+ } as $stored
436
+ }
437
+ response = $stored
438
+ }
439
+ ```
440
+
441
+ ---
442
+
443
+ ## ai.speech.generate
444
+
445
+ Read text aloud (text to speech).
446
+
447
+ | Key | Default | Notes |
448
+ |-----|---------|-------|
449
+ | `model` | `"gemini-3.8-flash-tts"` | a TTS model from the table |
450
+ | `text` | — | required; the words to speak |
451
+ | `voice` | `"Kore"` | a Gemini prebuilt voice name |
452
+ | `instructions` | `""` | a style prompt, e.g. `"say cheerfully"` |
453
+ | `save_to_files` | `""` | `""` (off), `"public"` or `"private"`; shortcut for `storage.create_audio` |
454
+
455
+ **Output:** `{audio, model, usage}`. `audio` is the stored file object when `save_to_files` is set, else a temporary file resource (`audio/wav`).
456
+
457
+ Store the narration on a row with the shortcut:
458
+
459
+ ```xs
460
+ function "narrate_article" {
461
+ input {
462
+ int article_id
463
+ text body
464
+ }
465
+ stack {
466
+ ai.speech.generate {
467
+ model = "gemini-3.8-flash-tts"
468
+ text = $input.body
469
+ voice = "Puck"
470
+ instructions = "Read calmly, like a radio host"
471
+ save_to_files = "public"
472
+ } as $speech
473
+
474
+ db.edit "article" {
475
+ field_name = "id"
476
+ field_value = $input.article_id
477
+ data = {
478
+ narration: $speech.audio
479
+ }
480
+ } as $article
481
+ }
482
+ response = $article
483
+ }
484
+ ```
485
+
486
+ The same with the explicit From File statement:
487
+
488
+ ```xs
489
+ function "narrate_article_explicit" {
490
+ input {
491
+ int article_id
492
+ text body
493
+ }
494
+ stack {
495
+ ai.speech.generate {
496
+ model = "gemini-3.8-flash-tts"
497
+ text = $input.body
498
+ } as $speech
499
+
500
+ storage.create_audio {
501
+ value = $speech.audio
502
+ access = "public"
503
+ filename = "narration.wav"
504
+ } as $stored
505
+
506
+ db.edit "article" {
507
+ field_name = "id"
508
+ field_value = $input.article_id
509
+ data = {
510
+ narration: $stored
511
+ }
512
+ } as $article
513
+ }
514
+ response = $article
515
+ }
516
+ ```
517
+
518
+ Return the stored file from an API endpoint, with the model and usage alongside it:
519
+
520
+ ```xs
521
+ query "speak" verb=POST {
522
+ api_group = "ai"
523
+ input {
524
+ text text
525
+ }
526
+ stack {
527
+ ai.speech.generate {
528
+ model = "gemini-3.8-flash-tts"
529
+ text = $input.text
530
+ save_to_files = "public"
531
+ } as $speech
532
+ }
533
+ response = $speech
534
+ }
535
+ ```
536
+
537
+ ```json
538
+ {
539
+ "audio": {
540
+ "access": "public",
541
+ "path": "/vault/…/speech.wav",
542
+ "name": "speech.wav",
543
+ "type": "audio",
544
+ "size": 214444,
545
+ "mime": "audio/wav",
546
+ "meta": {…},
547
+ "url": "https://…/vault/…/speech.wav"
548
+ },
549
+ "model": "gemini-3.8-flash-tts",
550
+ "usage": {"input_tokens": 13, "output_tokens": 107}
551
+ }
552
+ ```
553
+
554
+ ---
555
+
556
+ ## ai.speech.transcribe
557
+
558
+ Turn audio into text (speech to text).
559
+
560
+ | Key | Default | Notes |
561
+ |-----|---------|-------|
562
+ | `model` | `"gemini-3.5-transcribe"` | |
563
+ | `audio` | — | required; a file resource |
564
+ | `language` | `""` | BCP-47 hint, e.g. `"en-US"`; empty auto-detects |
565
+ | `prompt` | `""` | extra instructions or vocabulary (names, jargon) |
566
+
567
+ **Output:** `{text, model, usage}`.
568
+
569
+ ```xs
570
+ function "transcribe_voice_note" {
571
+ input {
572
+ file? recording
573
+ }
574
+ stack {
575
+ ai.speech.transcribe {
576
+ model = "gemini-3.5-transcribe"
577
+ audio = $input.recording
578
+ language = "en-US"
579
+ prompt = "Product names: Xano, XanoScript, Metadata API"
580
+ } as $transcript
581
+
582
+ db.add "voice_note" {
583
+ data = {
584
+ transcript: $transcript.text
585
+ }
586
+ } as $note
587
+ }
588
+ response = $note
589
+ }
590
+ ```
591
+
592
+ ---
593
+
594
+ ## ai.embedding.create
595
+
596
+ Turn text or media into embedding vectors. One embedding per input, in input order.
597
+
598
+ | Key | Default | Notes |
599
+ |-----|---------|-------|
600
+ | `model` | `"gemini-embedding-2"` | `gemini-embedding-001` is text only |
601
+ | `input` | — | required; text, a file resource, or a list of either |
602
+ | `task_type` | `""` | `RETRIEVAL_QUERY`, `RETRIEVAL_DOCUMENT`, `SEMANTIC_SIMILARITY`, `CLASSIFICATION`, `CLUSTERING`, `QUESTION_ANSWERING`, `FACT_VERIFICATION` |
603
+ | `dimensions` | `null` | int output size; `null` uses the model default. Must match your `vector` column `size` |
604
+
605
+ **Output:** `{embeddings, model, usage}`. `embeddings` is `[[float, ...], ...]`, one per input.
606
+
607
+ Embed documents and store the vectors (the `document` table has a `vector? embedding? { size = 768 }` column with a vector index, see `tables`):
608
+
609
+ ```xs
610
+ function "index_documents" {
611
+ input {
612
+ text[] contents
613
+ }
614
+ stack {
615
+ ai.embedding.create {
616
+ model = "gemini-embedding-2"
617
+ input = $input.contents
618
+ task_type = "RETRIEVAL_DOCUMENT"
619
+ dimensions = 768
620
+ } as $vectors
621
+
622
+ // embeddings[i] belongs to contents[i]
623
+ for ($input.contents|count) {
624
+ each as $i {
625
+ db.add "document" {
626
+ data = {
627
+ content: $input.contents|get:$i
628
+ embedding: $vectors.embeddings|get:$i
629
+ }
630
+ } as $doc
631
+ }
632
+ }
633
+ }
634
+ response = $vectors.embeddings|count
635
+ }
636
+ ```
637
+
638
+ Embed a query with `RETRIEVAL_QUERY` and search with `cosine_distance` (see `database`, Vector Search):
639
+
640
+ ```xs
641
+ function "search_documents" {
642
+ input {
643
+ text query
644
+ }
645
+ stack {
646
+ ai.embedding.create {
647
+ model = "gemini-embedding-2"
648
+ input = $input.query
649
+ task_type = "RETRIEVAL_QUERY"
650
+ dimensions = 768
651
+ } as $q
652
+
653
+ var $query_vector {
654
+ value = $q.embeddings|get:0
655
+ }
656
+
657
+ db.query "document" {
658
+ sort = {distance: "asc"}
659
+ eval = {
660
+ distance: $db.document.embedding|cosine_distance:$query_vector
661
+ }
662
+ return = {
663
+ type: "list"
664
+ paging: {page: 1, per_page: 20, metadata: false}
665
+ }
666
+ } as $candidates
667
+ }
668
+ response = $candidates
669
+ }
670
+ ```
671
+
672
+ Use the same `model` and `dimensions` for documents and queries; vectors from different models are not comparable.
673
+
674
+ ---
675
+
676
+ ## ai.rerank
677
+
678
+ Re-order documents by relevance to a query. Typical use: take the top 20 to 50 vector-search hits and keep the best few.
679
+
680
+ | Key | Default | Notes |
681
+ |-----|---------|-------|
682
+ | `model` | `"semantic-ranker-default-005"` | |
683
+ | `query` | — | required |
684
+ | `documents` | — | required; a list of text, or of `{id?, title?, content}` objects |
685
+ | `top_n` | `null` | int; `null` returns every document |
686
+
687
+ **Output:** `{results, model}`. `results` is `[{index, id, score, content}]`, best first. `index` is the position in `documents`; `id` is the document's `id` (if given).
688
+
689
+ Rerank search results:
690
+
691
+ ```xs
692
+ function "answer_sources" {
693
+ input {
694
+ text query
695
+ }
696
+ stack {
697
+ function.run "search_documents" {
698
+ input = {query: $input.query}
699
+ } as $candidates
700
+
701
+ ai.rerank {
702
+ model = "semantic-ranker-default-005"
703
+ query = $input.query
704
+ documents = $candidates|map:{id: $$.id, content: $$.content}
705
+ top_n = 5
706
+ } as $ranked
707
+ }
708
+ response = $ranked.results
709
+ }
710
+ ```
711
+
712
+ ---
713
+
714
+ ## ai.music.generate
715
+
716
+ Create a music clip (or, with the Lyria 3 models, a clip or full song with vocals).
717
+
718
+ | Key | Default | Notes |
719
+ |-----|---------|-------|
720
+ | `model` | `"lyria-002"` | `lyria-002`: 32.8 s instrumental WAV; `lyria-3-clip-preview`: 30 s clip, MP3; `lyria-3-pro-preview`: full song up to 184 s, vocals, MP3 |
721
+ | `prompt` | — | required |
722
+ | `negative_prompt` | `""` | what to avoid; **`lyria-002` only** (refused on Lyria 3) |
723
+ | `seed` | `null` | int, for repeatable results; **`lyria-002` only** (refused on Lyria 3) |
724
+ | `save_to_files` | `""` | `""` (off), `"public"` or `"private"`; shortcut for `storage.create_audio` |
725
+
726
+ **Output:** `{audio, lyrics, description, model}`. `audio` is the stored file object when `save_to_files` is set, else a temporary file resource (WAV on `lyria-002`, MP3 on Lyria 3). `lyrics` and `description` are strings from the Lyria 3 models, or `null` when the model returns none (always `null` on `lyria-002`).
727
+
728
+ Store the jingle with the explicit From File statement (`storage.create_audio`):
729
+
730
+ ```xs
731
+ function "make_intro_jingle" {
732
+ input {
733
+ }
734
+ stack {
735
+ ai.music.generate {
736
+ model = "lyria-002"
737
+ prompt = "Upbeat lo-fi hip hop intro, mellow keys, light vinyl crackle"
738
+ negative_prompt = "vocals, distortion"
739
+ seed = 42
740
+ } as $music
741
+
742
+ storage.create_audio {
743
+ value = $music.audio
744
+ access = "public"
745
+ filename = "intro.wav"
746
+ } as $stored
747
+ }
748
+ response = $stored
749
+ }
750
+ ```
751
+
752
+ A song with Lyria 3, stored with the shortcut (no `negative_prompt` or `seed` here):
753
+
754
+ ```xs
755
+ function "make_theme_song" {
756
+ input {
757
+ }
758
+ stack {
759
+ ai.music.generate {
760
+ model = "lyria-3-pro-preview"
761
+ prompt = "Cheerful indie pop song about shipping code on a Friday, female vocals"
762
+ save_to_files = "public"
763
+ } as $song
764
+
765
+ db.add "song" {
766
+ data = {
767
+ audio: $song.audio
768
+ lyrics: $song.lyrics
769
+ description: $song.description
770
+ }
771
+ } as $row
772
+ }
773
+ response = $row
774
+ }
775
+ ```
776
+
777
+ ---
778
+
779
+ ## Common Mistakes
780
+
781
+ 1. **Adding an `api_key` or `provider`.** These statements bill Xano AI credits only; the keys do not exist. Use `api.request` or an agent provider for your own key.
782
+ 2. **Expecting media to be saved.** `image`/`video`/`audio` are temporary file resources. Set `save_to_files`, or store them with `storage.create_image` / `storage.create_video` / `storage.create_audio`, or they are gone after the request.
783
+ 3. **Using `ai.agent.run` for a single call.** An agent is for tools and multi-step work. A single prompt-to-answer is `ai.text.generate`.
784
+ 4. **Reading `$result.json` without `response_format = "json"`.** `json` is `null` for text responses.
785
+ 5. **Mismatched embedding sizes.** `dimensions` must match the `vector` column `size`, and documents and queries must use the same model.
786
+ 6. **A model from the wrong statement.** Each statement accepts only its own catalog models (an image model on `ai.text.generate` is refused).
787
+ 7. **Putting `$result.image` / `$result.audio` / `$result.video` straight into a file column.** That is a temporary file resource, and the column saves `null`. Set `save_to_files = "public"` (or `"private"`) on the statement (the key then holds the stored file), or use the result of the From File statement (`storage.create_image` / `storage.create_video` / `storage.create_audio`).
788
+
789
+ ```xs
790
+ // ❌ saves null (no save_to_files: $result.image is a file resource)
791
+ db.add "gallery" {
792
+ data = {image: $result.image}
793
+ } as $row
794
+
795
+ // ✅ save_to_files set: $result.image is the stored file
796
+ ai.image.generate {
797
+ model = "gemini-3.1-flash-image"
798
+ prompt = "A red fox, watercolor"
799
+ save_to_files = "public"
800
+ } as $result
801
+
802
+ db.add "gallery" {
803
+ data = {image: $result.image}
804
+ } as $row
805
+ ```
806
+
807
+ 8. **`negative_prompt` or `seed` on a Lyria 3 model.** They are `lyria-002` only; `lyria-3-clip-preview` and `lyria-3-pro-preview` refuse them with an error naming the model.
808
+ 9. **`save_to_files` on `ai.text.generate`, `ai.speech.transcribe`, `ai.embedding.create` or `ai.rerank`.** Only the four media statements have it; elsewhere it is an unknown key.
809
+
810
+ ---
811
+
812
+ ## Related Topics
813
+
814
+ | Topic | Description |
815
+ |-------|-------------|
816
+ | `agents` | `ai.agent.run`, for tools and multi-step work |
817
+ | `file-uploads` | `file?` inputs and storing files with `storage.create_image` / `storage.create_video` / `storage.create_audio` / `storage.create_attachment` |
818
+ | `database` | Vector search with `cosine_distance` |
819
+ | `tables` | `vector` columns and vector indexes |
820
+ | `integrations/external-apis` | `api.request`, for calling a model with your own API key |