ai 6.0.31 → 6.0.33
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.
- package/CHANGELOG.md +12 -0
- package/dist/index.js +12 -2
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +12 -2
- package/dist/index.mjs.map +1 -1
- package/dist/internal/index.js +1 -1
- package/dist/internal/index.mjs +1 -1
- package/docs/00-introduction/index.mdx +76 -0
- package/docs/02-foundations/01-overview.mdx +43 -0
- package/docs/02-foundations/02-providers-and-models.mdx +163 -0
- package/docs/02-foundations/03-prompts.mdx +620 -0
- package/docs/02-foundations/04-tools.mdx +160 -0
- package/docs/02-foundations/05-streaming.mdx +62 -0
- package/docs/02-foundations/index.mdx +43 -0
- package/docs/02-getting-started/00-choosing-a-provider.mdx +110 -0
- package/docs/02-getting-started/01-navigating-the-library.mdx +85 -0
- package/docs/02-getting-started/02-nextjs-app-router.mdx +556 -0
- package/docs/02-getting-started/03-nextjs-pages-router.mdx +542 -0
- package/docs/02-getting-started/04-svelte.mdx +627 -0
- package/docs/02-getting-started/05-nuxt.mdx +566 -0
- package/docs/02-getting-started/06-nodejs.mdx +512 -0
- package/docs/02-getting-started/07-expo.mdx +766 -0
- package/docs/02-getting-started/08-tanstack-start.mdx +583 -0
- package/docs/02-getting-started/index.mdx +44 -0
- package/docs/03-agents/01-overview.mdx +96 -0
- package/docs/03-agents/02-building-agents.mdx +367 -0
- package/docs/03-agents/03-workflows.mdx +370 -0
- package/docs/03-agents/04-loop-control.mdx +350 -0
- package/docs/03-agents/05-configuring-call-options.mdx +286 -0
- package/docs/03-agents/index.mdx +40 -0
- package/docs/03-ai-sdk-core/01-overview.mdx +33 -0
- package/docs/03-ai-sdk-core/05-generating-text.mdx +600 -0
- package/docs/03-ai-sdk-core/10-generating-structured-data.mdx +662 -0
- package/docs/03-ai-sdk-core/15-tools-and-tool-calling.mdx +1102 -0
- package/docs/03-ai-sdk-core/16-mcp-tools.mdx +375 -0
- package/docs/03-ai-sdk-core/20-prompt-engineering.mdx +144 -0
- package/docs/03-ai-sdk-core/25-settings.mdx +198 -0
- package/docs/03-ai-sdk-core/30-embeddings.mdx +247 -0
- package/docs/03-ai-sdk-core/31-reranking.mdx +218 -0
- package/docs/03-ai-sdk-core/35-image-generation.mdx +341 -0
- package/docs/03-ai-sdk-core/36-transcription.mdx +173 -0
- package/docs/03-ai-sdk-core/37-speech.mdx +167 -0
- package/docs/03-ai-sdk-core/40-middleware.mdx +480 -0
- package/docs/03-ai-sdk-core/45-provider-management.mdx +349 -0
- package/docs/03-ai-sdk-core/50-error-handling.mdx +149 -0
- package/docs/03-ai-sdk-core/55-testing.mdx +218 -0
- package/docs/03-ai-sdk-core/60-telemetry.mdx +313 -0
- package/docs/03-ai-sdk-core/65-devtools.mdx +107 -0
- package/docs/03-ai-sdk-core/index.mdx +88 -0
- package/docs/04-ai-sdk-ui/01-overview.mdx +44 -0
- package/docs/04-ai-sdk-ui/02-chatbot.mdx +1313 -0
- package/docs/04-ai-sdk-ui/03-chatbot-message-persistence.mdx +535 -0
- package/docs/04-ai-sdk-ui/03-chatbot-resume-streams.mdx +263 -0
- package/docs/04-ai-sdk-ui/03-chatbot-tool-usage.mdx +682 -0
- package/docs/04-ai-sdk-ui/04-generative-user-interfaces.mdx +389 -0
- package/docs/04-ai-sdk-ui/05-completion.mdx +186 -0
- package/docs/04-ai-sdk-ui/08-object-generation.mdx +344 -0
- package/docs/04-ai-sdk-ui/20-streaming-data.mdx +397 -0
- package/docs/04-ai-sdk-ui/21-error-handling.mdx +190 -0
- package/docs/04-ai-sdk-ui/21-transport.mdx +174 -0
- package/docs/04-ai-sdk-ui/24-reading-ui-message-streams.mdx +104 -0
- package/docs/04-ai-sdk-ui/25-message-metadata.mdx +152 -0
- package/docs/04-ai-sdk-ui/50-stream-protocol.mdx +477 -0
- package/docs/04-ai-sdk-ui/index.mdx +64 -0
- package/docs/05-ai-sdk-rsc/01-overview.mdx +45 -0
- package/docs/05-ai-sdk-rsc/02-streaming-react-components.mdx +209 -0
- package/docs/05-ai-sdk-rsc/03-generative-ui-state.mdx +279 -0
- package/docs/05-ai-sdk-rsc/03-saving-and-restoring-states.mdx +105 -0
- package/docs/05-ai-sdk-rsc/04-multistep-interfaces.mdx +282 -0
- package/docs/05-ai-sdk-rsc/05-streaming-values.mdx +158 -0
- package/docs/05-ai-sdk-rsc/06-loading-state.mdx +273 -0
- package/docs/05-ai-sdk-rsc/08-error-handling.mdx +96 -0
- package/docs/05-ai-sdk-rsc/09-authentication.mdx +42 -0
- package/docs/05-ai-sdk-rsc/10-migrating-to-ui.mdx +722 -0
- package/docs/05-ai-sdk-rsc/index.mdx +58 -0
- package/docs/06-advanced/01-prompt-engineering.mdx +96 -0
- package/docs/06-advanced/02-stopping-streams.mdx +184 -0
- package/docs/06-advanced/03-backpressure.mdx +173 -0
- package/docs/06-advanced/04-caching.mdx +169 -0
- package/docs/06-advanced/05-multiple-streamables.mdx +68 -0
- package/docs/06-advanced/06-rate-limiting.mdx +60 -0
- package/docs/06-advanced/07-rendering-ui-with-language-models.mdx +213 -0
- package/docs/06-advanced/08-model-as-router.mdx +120 -0
- package/docs/06-advanced/09-multistep-interfaces.mdx +115 -0
- package/docs/06-advanced/09-sequential-generations.mdx +55 -0
- package/docs/06-advanced/10-vercel-deployment-guide.mdx +117 -0
- package/docs/06-advanced/index.mdx +11 -0
- package/docs/07-reference/01-ai-sdk-core/01-generate-text.mdx +2142 -0
- package/docs/07-reference/01-ai-sdk-core/02-stream-text.mdx +3215 -0
- package/docs/07-reference/01-ai-sdk-core/03-generate-object.mdx +780 -0
- package/docs/07-reference/01-ai-sdk-core/04-stream-object.mdx +1140 -0
- package/docs/07-reference/01-ai-sdk-core/05-embed.mdx +190 -0
- package/docs/07-reference/01-ai-sdk-core/06-embed-many.mdx +171 -0
- package/docs/07-reference/01-ai-sdk-core/06-rerank.mdx +309 -0
- package/docs/07-reference/01-ai-sdk-core/10-generate-image.mdx +227 -0
- package/docs/07-reference/01-ai-sdk-core/11-transcribe.mdx +138 -0
- package/docs/07-reference/01-ai-sdk-core/12-generate-speech.mdx +214 -0
- package/docs/07-reference/01-ai-sdk-core/15-agent.mdx +203 -0
- package/docs/07-reference/01-ai-sdk-core/16-tool-loop-agent.mdx +449 -0
- package/docs/07-reference/01-ai-sdk-core/17-create-agent-ui-stream.mdx +148 -0
- package/docs/07-reference/01-ai-sdk-core/18-create-agent-ui-stream-response.mdx +168 -0
- package/docs/07-reference/01-ai-sdk-core/18-pipe-agent-ui-stream-to-response.mdx +144 -0
- package/docs/07-reference/01-ai-sdk-core/20-tool.mdx +196 -0
- package/docs/07-reference/01-ai-sdk-core/22-dynamic-tool.mdx +175 -0
- package/docs/07-reference/01-ai-sdk-core/23-create-mcp-client.mdx +410 -0
- package/docs/07-reference/01-ai-sdk-core/24-mcp-stdio-transport.mdx +68 -0
- package/docs/07-reference/01-ai-sdk-core/25-json-schema.mdx +94 -0
- package/docs/07-reference/01-ai-sdk-core/26-zod-schema.mdx +109 -0
- package/docs/07-reference/01-ai-sdk-core/27-valibot-schema.mdx +55 -0
- package/docs/07-reference/01-ai-sdk-core/28-output.mdx +342 -0
- package/docs/07-reference/01-ai-sdk-core/30-model-message.mdx +415 -0
- package/docs/07-reference/01-ai-sdk-core/31-ui-message.mdx +246 -0
- package/docs/07-reference/01-ai-sdk-core/32-validate-ui-messages.mdx +101 -0
- package/docs/07-reference/01-ai-sdk-core/33-safe-validate-ui-messages.mdx +113 -0
- package/docs/07-reference/01-ai-sdk-core/40-provider-registry.mdx +182 -0
- package/docs/07-reference/01-ai-sdk-core/42-custom-provider.mdx +121 -0
- package/docs/07-reference/01-ai-sdk-core/50-cosine-similarity.mdx +52 -0
- package/docs/07-reference/01-ai-sdk-core/60-wrap-language-model.mdx +59 -0
- package/docs/07-reference/01-ai-sdk-core/61-wrap-image-model.mdx +64 -0
- package/docs/07-reference/01-ai-sdk-core/65-language-model-v2-middleware.mdx +46 -0
- package/docs/07-reference/01-ai-sdk-core/66-extract-reasoning-middleware.mdx +68 -0
- package/docs/07-reference/01-ai-sdk-core/67-simulate-streaming-middleware.mdx +71 -0
- package/docs/07-reference/01-ai-sdk-core/68-default-settings-middleware.mdx +80 -0
- package/docs/07-reference/01-ai-sdk-core/69-add-tool-input-examples-middleware.mdx +155 -0
- package/docs/07-reference/01-ai-sdk-core/70-extract-json-middleware.mdx +147 -0
- package/docs/07-reference/01-ai-sdk-core/70-step-count-is.mdx +84 -0
- package/docs/07-reference/01-ai-sdk-core/71-has-tool-call.mdx +120 -0
- package/docs/07-reference/01-ai-sdk-core/75-simulate-readable-stream.mdx +94 -0
- package/docs/07-reference/01-ai-sdk-core/80-smooth-stream.mdx +145 -0
- package/docs/07-reference/01-ai-sdk-core/90-generate-id.mdx +43 -0
- package/docs/07-reference/01-ai-sdk-core/91-create-id-generator.mdx +89 -0
- package/docs/07-reference/01-ai-sdk-core/index.mdx +159 -0
- package/docs/07-reference/02-ai-sdk-ui/01-use-chat.mdx +446 -0
- package/docs/07-reference/02-ai-sdk-ui/02-use-completion.mdx +179 -0
- package/docs/07-reference/02-ai-sdk-ui/03-use-object.mdx +178 -0
- package/docs/07-reference/02-ai-sdk-ui/31-convert-to-model-messages.mdx +230 -0
- package/docs/07-reference/02-ai-sdk-ui/32-prune-messages.mdx +108 -0
- package/docs/07-reference/02-ai-sdk-ui/40-create-ui-message-stream.mdx +151 -0
- package/docs/07-reference/02-ai-sdk-ui/41-create-ui-message-stream-response.mdx +113 -0
- package/docs/07-reference/02-ai-sdk-ui/42-pipe-ui-message-stream-to-response.mdx +73 -0
- package/docs/07-reference/02-ai-sdk-ui/43-read-ui-message-stream.mdx +57 -0
- package/docs/07-reference/02-ai-sdk-ui/46-infer-ui-tools.mdx +99 -0
- package/docs/07-reference/02-ai-sdk-ui/47-infer-ui-tool.mdx +75 -0
- package/docs/07-reference/02-ai-sdk-ui/50-direct-chat-transport.mdx +333 -0
- package/docs/07-reference/02-ai-sdk-ui/index.mdx +89 -0
- package/docs/07-reference/03-ai-sdk-rsc/01-stream-ui.mdx +767 -0
- package/docs/07-reference/03-ai-sdk-rsc/02-create-ai.mdx +90 -0
- package/docs/07-reference/03-ai-sdk-rsc/03-create-streamable-ui.mdx +91 -0
- package/docs/07-reference/03-ai-sdk-rsc/04-create-streamable-value.mdx +48 -0
- package/docs/07-reference/03-ai-sdk-rsc/05-read-streamable-value.mdx +78 -0
- package/docs/07-reference/03-ai-sdk-rsc/06-get-ai-state.mdx +50 -0
- package/docs/07-reference/03-ai-sdk-rsc/07-get-mutable-ai-state.mdx +70 -0
- package/docs/07-reference/03-ai-sdk-rsc/08-use-ai-state.mdx +26 -0
- package/docs/07-reference/03-ai-sdk-rsc/09-use-actions.mdx +42 -0
- package/docs/07-reference/03-ai-sdk-rsc/10-use-ui-state.mdx +35 -0
- package/docs/07-reference/03-ai-sdk-rsc/11-use-streamable-value.mdx +46 -0
- package/docs/07-reference/03-ai-sdk-rsc/20-render.mdx +262 -0
- package/docs/07-reference/03-ai-sdk-rsc/index.mdx +67 -0
- package/docs/07-reference/04-stream-helpers/01-ai-stream.mdx +89 -0
- package/docs/07-reference/04-stream-helpers/02-streaming-text-response.mdx +79 -0
- package/docs/07-reference/04-stream-helpers/05-stream-to-response.mdx +108 -0
- package/docs/07-reference/04-stream-helpers/07-openai-stream.mdx +77 -0
- package/docs/07-reference/04-stream-helpers/08-anthropic-stream.mdx +79 -0
- package/docs/07-reference/04-stream-helpers/09-aws-bedrock-stream.mdx +91 -0
- package/docs/07-reference/04-stream-helpers/10-aws-bedrock-anthropic-stream.mdx +96 -0
- package/docs/07-reference/04-stream-helpers/10-aws-bedrock-messages-stream.mdx +96 -0
- package/docs/07-reference/04-stream-helpers/11-aws-bedrock-cohere-stream.mdx +93 -0
- package/docs/07-reference/04-stream-helpers/12-aws-bedrock-llama-2-stream.mdx +93 -0
- package/docs/07-reference/04-stream-helpers/13-cohere-stream.mdx +78 -0
- package/docs/07-reference/04-stream-helpers/14-google-generative-ai-stream.mdx +85 -0
- package/docs/07-reference/04-stream-helpers/15-hugging-face-stream.mdx +84 -0
- package/docs/07-reference/04-stream-helpers/16-langchain-adapter.mdx +98 -0
- package/docs/07-reference/04-stream-helpers/16-llamaindex-adapter.mdx +70 -0
- package/docs/07-reference/04-stream-helpers/17-mistral-stream.mdx +81 -0
- package/docs/07-reference/04-stream-helpers/18-replicate-stream.mdx +83 -0
- package/docs/07-reference/04-stream-helpers/19-inkeep-stream.mdx +80 -0
- package/docs/07-reference/04-stream-helpers/index.mdx +103 -0
- package/docs/07-reference/05-ai-sdk-errors/ai-api-call-error.mdx +30 -0
- package/docs/07-reference/05-ai-sdk-errors/ai-download-error.mdx +27 -0
- package/docs/07-reference/05-ai-sdk-errors/ai-empty-response-body-error.mdx +24 -0
- package/docs/07-reference/05-ai-sdk-errors/ai-invalid-argument-error.mdx +26 -0
- package/docs/07-reference/05-ai-sdk-errors/ai-invalid-data-content-error.mdx +25 -0
- package/docs/07-reference/05-ai-sdk-errors/ai-invalid-data-content.mdx +26 -0
- package/docs/07-reference/05-ai-sdk-errors/ai-invalid-message-role-error.mdx +25 -0
- package/docs/07-reference/05-ai-sdk-errors/ai-invalid-prompt-error.mdx +47 -0
- package/docs/07-reference/05-ai-sdk-errors/ai-invalid-response-data-error.mdx +25 -0
- package/docs/07-reference/05-ai-sdk-errors/ai-invalid-tool-approval-error.mdx +25 -0
- package/docs/07-reference/05-ai-sdk-errors/ai-invalid-tool-input-error.mdx +27 -0
- package/docs/07-reference/05-ai-sdk-errors/ai-json-parse-error.mdx +25 -0
- package/docs/07-reference/05-ai-sdk-errors/ai-load-api-key-error.mdx +24 -0
- package/docs/07-reference/05-ai-sdk-errors/ai-load-setting-error.mdx +24 -0
- package/docs/07-reference/05-ai-sdk-errors/ai-message-conversion-error.mdx +25 -0
- package/docs/07-reference/05-ai-sdk-errors/ai-no-content-generated-error.mdx +24 -0
- package/docs/07-reference/05-ai-sdk-errors/ai-no-image-generated-error.mdx +36 -0
- package/docs/07-reference/05-ai-sdk-errors/ai-no-object-generated-error.mdx +43 -0
- package/docs/07-reference/05-ai-sdk-errors/ai-no-speech-generated-error.mdx +25 -0
- package/docs/07-reference/05-ai-sdk-errors/ai-no-such-model-error.mdx +26 -0
- package/docs/07-reference/05-ai-sdk-errors/ai-no-such-provider-error.mdx +28 -0
- package/docs/07-reference/05-ai-sdk-errors/ai-no-such-tool-error.mdx +26 -0
- package/docs/07-reference/05-ai-sdk-errors/ai-no-transcript-generated-error.mdx +25 -0
- package/docs/07-reference/05-ai-sdk-errors/ai-retry-error.mdx +27 -0
- package/docs/07-reference/05-ai-sdk-errors/ai-too-many-embedding-values-for-call-error.mdx +27 -0
- package/docs/07-reference/05-ai-sdk-errors/ai-tool-call-not-found-for-approval-error.mdx +26 -0
- package/docs/07-reference/05-ai-sdk-errors/ai-tool-call-repair-error.mdx +28 -0
- package/docs/07-reference/05-ai-sdk-errors/ai-type-validation-error.mdx +25 -0
- package/docs/07-reference/05-ai-sdk-errors/ai-unsupported-functionality-error.mdx +25 -0
- package/docs/07-reference/05-ai-sdk-errors/index.mdx +38 -0
- package/docs/07-reference/index.mdx +34 -0
- package/docs/08-migration-guides/00-versioning.mdx +46 -0
- package/docs/08-migration-guides/24-migration-guide-6-0.mdx +823 -0
- package/docs/08-migration-guides/25-migration-guide-5-0-data.mdx +882 -0
- package/docs/08-migration-guides/26-migration-guide-5-0.mdx +3427 -0
- package/docs/08-migration-guides/27-migration-guide-4-2.mdx +99 -0
- package/docs/08-migration-guides/28-migration-guide-4-1.mdx +14 -0
- package/docs/08-migration-guides/29-migration-guide-4-0.mdx +1157 -0
- package/docs/08-migration-guides/36-migration-guide-3-4.mdx +14 -0
- package/docs/08-migration-guides/37-migration-guide-3-3.mdx +64 -0
- package/docs/08-migration-guides/38-migration-guide-3-2.mdx +46 -0
- package/docs/08-migration-guides/39-migration-guide-3-1.mdx +168 -0
- package/docs/08-migration-guides/index.mdx +22 -0
- package/docs/09-troubleshooting/01-azure-stream-slow.mdx +33 -0
- package/docs/09-troubleshooting/02-client-side-function-calls-not-invoked.mdx +22 -0
- package/docs/09-troubleshooting/03-server-actions-in-client-components.mdx +40 -0
- package/docs/09-troubleshooting/04-strange-stream-output.mdx +36 -0
- package/docs/09-troubleshooting/05-streamable-ui-errors.mdx +16 -0
- package/docs/09-troubleshooting/05-tool-invocation-missing-result.mdx +106 -0
- package/docs/09-troubleshooting/06-streaming-not-working-when-deployed.mdx +31 -0
- package/docs/09-troubleshooting/06-streaming-not-working-when-proxied.mdx +31 -0
- package/docs/09-troubleshooting/06-timeout-on-vercel.mdx +60 -0
- package/docs/09-troubleshooting/07-unclosed-streams.mdx +34 -0
- package/docs/09-troubleshooting/08-use-chat-failed-to-parse-stream.mdx +26 -0
- package/docs/09-troubleshooting/09-client-stream-error.mdx +25 -0
- package/docs/09-troubleshooting/10-use-chat-tools-no-response.mdx +32 -0
- package/docs/09-troubleshooting/11-use-chat-custom-request-options.mdx +149 -0
- package/docs/09-troubleshooting/12-typescript-performance-zod.mdx +46 -0
- package/docs/09-troubleshooting/12-use-chat-an-error-occurred.mdx +59 -0
- package/docs/09-troubleshooting/13-repeated-assistant-messages.mdx +73 -0
- package/docs/09-troubleshooting/14-stream-abort-handling.mdx +73 -0
- package/docs/09-troubleshooting/14-tool-calling-with-structured-outputs.mdx +48 -0
- package/docs/09-troubleshooting/15-abort-breaks-resumable-streams.mdx +55 -0
- package/docs/09-troubleshooting/15-stream-text-not-working.mdx +33 -0
- package/docs/09-troubleshooting/16-streaming-status-delay.mdx +63 -0
- package/docs/09-troubleshooting/17-use-chat-stale-body-data.mdx +141 -0
- package/docs/09-troubleshooting/18-ontoolcall-type-narrowing.mdx +66 -0
- package/docs/09-troubleshooting/19-unsupported-model-version.mdx +50 -0
- package/docs/09-troubleshooting/20-no-object-generated-content-filter.mdx +72 -0
- package/docs/09-troubleshooting/30-model-is-not-assignable-to-type.mdx +21 -0
- package/docs/09-troubleshooting/40-typescript-cannot-find-namespace-jsx.mdx +24 -0
- package/docs/09-troubleshooting/50-react-maximum-update-depth-exceeded.mdx +39 -0
- package/docs/09-troubleshooting/60-jest-cannot-find-module-ai-rsc.mdx +22 -0
- package/docs/09-troubleshooting/index.mdx +11 -0
- package/package.json +8 -4
|
@@ -0,0 +1,780 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: generateObject
|
|
3
|
+
description: API Reference for generateObject.
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
# `generateObject()`
|
|
7
|
+
|
|
8
|
+
<Note type="warning">
|
|
9
|
+
`generateObject` is deprecated. Use
|
|
10
|
+
[`generateText`](/docs/reference/ai-sdk-core/generate-text) with the
|
|
11
|
+
[`output`](/docs/reference/ai-sdk-core/output) property instead. See
|
|
12
|
+
[Generating Structured Data](/docs/ai-sdk-core/generating-structured-data) for
|
|
13
|
+
more information.
|
|
14
|
+
</Note>
|
|
15
|
+
|
|
16
|
+
Generates a typed, structured object for a given prompt and schema using a language model.
|
|
17
|
+
|
|
18
|
+
It can be used to force the language model to return structured data, e.g. for information extraction, synthetic data generation, or classification tasks.
|
|
19
|
+
|
|
20
|
+
#### Example: generate an object using a schema
|
|
21
|
+
|
|
22
|
+
```ts
|
|
23
|
+
import { generateObject } from 'ai';
|
|
24
|
+
__PROVIDER_IMPORT__;
|
|
25
|
+
import { z } from 'zod';
|
|
26
|
+
|
|
27
|
+
const { object } = await generateObject({
|
|
28
|
+
model: __MODEL__,
|
|
29
|
+
schema: z.object({
|
|
30
|
+
recipe: z.object({
|
|
31
|
+
name: z.string(),
|
|
32
|
+
ingredients: z.array(z.string()),
|
|
33
|
+
steps: z.array(z.string()),
|
|
34
|
+
}),
|
|
35
|
+
}),
|
|
36
|
+
prompt: 'Generate a lasagna recipe.',
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
console.log(JSON.stringify(object, null, 2));
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
#### Example: generate an array using a schema
|
|
43
|
+
|
|
44
|
+
For arrays, you specify the schema of the array items.
|
|
45
|
+
|
|
46
|
+
```ts highlight="7"
|
|
47
|
+
import { generateObject } from 'ai';
|
|
48
|
+
__PROVIDER_IMPORT__;
|
|
49
|
+
import { z } from 'zod';
|
|
50
|
+
|
|
51
|
+
const { object } = await generateObject({
|
|
52
|
+
model: __MODEL__,
|
|
53
|
+
output: 'array',
|
|
54
|
+
schema: z.object({
|
|
55
|
+
name: z.string(),
|
|
56
|
+
class: z
|
|
57
|
+
.string()
|
|
58
|
+
.describe('Character class, e.g. warrior, mage, or thief.'),
|
|
59
|
+
description: z.string(),
|
|
60
|
+
}),
|
|
61
|
+
prompt: 'Generate 3 hero descriptions for a fantasy role playing game.',
|
|
62
|
+
});
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
#### Example: generate an enum
|
|
66
|
+
|
|
67
|
+
When you want to generate a specific enum value, you can set the output strategy to `enum`
|
|
68
|
+
and provide the list of possible values in the `enum` parameter.
|
|
69
|
+
|
|
70
|
+
```ts highlight="5-6"
|
|
71
|
+
import { generateObject } from 'ai';
|
|
72
|
+
|
|
73
|
+
const { object } = await generateObject({
|
|
74
|
+
model: __MODEL__,
|
|
75
|
+
output: 'enum',
|
|
76
|
+
enum: ['action', 'comedy', 'drama', 'horror', 'sci-fi'],
|
|
77
|
+
prompt:
|
|
78
|
+
'Classify the genre of this movie plot: ' +
|
|
79
|
+
'"A group of astronauts travel through a wormhole in search of a ' +
|
|
80
|
+
'new habitable planet for humanity."',
|
|
81
|
+
});
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
#### Example: generate JSON without a schema
|
|
85
|
+
|
|
86
|
+
```ts highlight="6"
|
|
87
|
+
import { generateObject } from 'ai';
|
|
88
|
+
|
|
89
|
+
const { object } = await generateObject({
|
|
90
|
+
model: __MODEL__,
|
|
91
|
+
output: 'no-schema',
|
|
92
|
+
prompt: 'Generate a lasagna recipe.',
|
|
93
|
+
});
|
|
94
|
+
```
|
|
95
|
+
|
|
96
|
+
To see `generateObject` in action, check out the [additional examples](#more-examples).
|
|
97
|
+
|
|
98
|
+
## Import
|
|
99
|
+
|
|
100
|
+
<Snippet text={`import { generateObject } from "ai"`} prompt={false} />
|
|
101
|
+
|
|
102
|
+
## API Signature
|
|
103
|
+
|
|
104
|
+
### Parameters
|
|
105
|
+
|
|
106
|
+
<PropertiesTable
|
|
107
|
+
content={[
|
|
108
|
+
{
|
|
109
|
+
name: 'model',
|
|
110
|
+
type: 'LanguageModel',
|
|
111
|
+
description: "The language model to use. Example: openai('gpt-4.1')",
|
|
112
|
+
},
|
|
113
|
+
{
|
|
114
|
+
name: 'output',
|
|
115
|
+
type: "'object' | 'array' | 'enum' | 'no-schema' | undefined",
|
|
116
|
+
description: "The type of output to generate. Defaults to 'object'.",
|
|
117
|
+
},
|
|
118
|
+
{
|
|
119
|
+
name: 'schema',
|
|
120
|
+
type: 'Zod Schema | JSON Schema',
|
|
121
|
+
description:
|
|
122
|
+
"The schema that describes the shape of the object to generate. \
|
|
123
|
+
It is sent to the model to generate the object and used to validate the output. \
|
|
124
|
+
You can either pass in a Zod schema or a JSON schema (using the `jsonSchema` function). \
|
|
125
|
+
In 'array' mode, the schema is used to describe an array element. \
|
|
126
|
+
Not available with 'no-schema' or 'enum' output.",
|
|
127
|
+
},
|
|
128
|
+
{
|
|
129
|
+
name: 'schemaName',
|
|
130
|
+
type: 'string | undefined',
|
|
131
|
+
description:
|
|
132
|
+
"Optional name of the output that should be generated. \
|
|
133
|
+
Used by some providers for additional LLM guidance, e.g. via tool or schema name. \
|
|
134
|
+
Not available with 'no-schema' or 'enum' output.",
|
|
135
|
+
},
|
|
136
|
+
{
|
|
137
|
+
name: 'schemaDescription',
|
|
138
|
+
type: 'string | undefined',
|
|
139
|
+
description:
|
|
140
|
+
"Optional description of the output that should be generated. \
|
|
141
|
+
Used by some providers for additional LLM guidance, e.g. via tool or schema name. \
|
|
142
|
+
Not available with 'no-schema' or 'enum' output.",
|
|
143
|
+
},
|
|
144
|
+
{
|
|
145
|
+
name: 'enum',
|
|
146
|
+
type: 'string[]',
|
|
147
|
+
description:
|
|
148
|
+
"List of possible values to generate. \
|
|
149
|
+
Only available with 'enum' output.",
|
|
150
|
+
},
|
|
151
|
+
{
|
|
152
|
+
name: 'system',
|
|
153
|
+
type: 'string | SystemModelMessage | SystemModelMessage[]',
|
|
154
|
+
description:
|
|
155
|
+
'The system prompt to use that specifies the behavior of the model.',
|
|
156
|
+
},
|
|
157
|
+
{
|
|
158
|
+
name: 'prompt',
|
|
159
|
+
type: 'string | Array<SystemModelMessage | UserModelMessage | AssistantModelMessage | ToolModelMessage>',
|
|
160
|
+
description: 'The input prompt to generate the text from.',
|
|
161
|
+
},
|
|
162
|
+
{
|
|
163
|
+
name: 'messages',
|
|
164
|
+
type: 'Array<SystemModelMessage | UserModelMessage | AssistantModelMessage | ToolModelMessage>',
|
|
165
|
+
description:
|
|
166
|
+
'A list of messages that represent a conversation. Automatically converts UI messages from the useChat hook.',
|
|
167
|
+
properties: [
|
|
168
|
+
{
|
|
169
|
+
type: 'SystemModelMessage',
|
|
170
|
+
parameters: [
|
|
171
|
+
{
|
|
172
|
+
name: 'role',
|
|
173
|
+
type: "'system'",
|
|
174
|
+
description: 'The role for the system message.',
|
|
175
|
+
},
|
|
176
|
+
{
|
|
177
|
+
name: 'content',
|
|
178
|
+
type: 'string',
|
|
179
|
+
description: 'The content of the message.',
|
|
180
|
+
},
|
|
181
|
+
],
|
|
182
|
+
},
|
|
183
|
+
{
|
|
184
|
+
type: 'UserModelMessage',
|
|
185
|
+
parameters: [
|
|
186
|
+
{
|
|
187
|
+
name: 'role',
|
|
188
|
+
type: "'user'",
|
|
189
|
+
description: 'The role for the user message.',
|
|
190
|
+
},
|
|
191
|
+
{
|
|
192
|
+
name: 'content',
|
|
193
|
+
type: 'string | Array<TextPart | ImagePart | FilePart>',
|
|
194
|
+
description: 'The content of the message.',
|
|
195
|
+
properties: [
|
|
196
|
+
{
|
|
197
|
+
type: 'TextPart',
|
|
198
|
+
parameters: [
|
|
199
|
+
{
|
|
200
|
+
name: 'type',
|
|
201
|
+
type: "'text'",
|
|
202
|
+
description: 'The type of the message part.',
|
|
203
|
+
},
|
|
204
|
+
{
|
|
205
|
+
name: 'text',
|
|
206
|
+
type: 'string',
|
|
207
|
+
description: 'The text content of the message part.',
|
|
208
|
+
},
|
|
209
|
+
],
|
|
210
|
+
},
|
|
211
|
+
{
|
|
212
|
+
type: 'ImagePart',
|
|
213
|
+
parameters: [
|
|
214
|
+
{
|
|
215
|
+
name: 'type',
|
|
216
|
+
type: "'image'",
|
|
217
|
+
description: 'The type of the message part.',
|
|
218
|
+
},
|
|
219
|
+
{
|
|
220
|
+
name: 'image',
|
|
221
|
+
type: 'string | Uint8Array | Buffer | ArrayBuffer | URL',
|
|
222
|
+
description:
|
|
223
|
+
'The image content of the message part. String are either base64 encoded content, base64 data URLs, or http(s) URLs.',
|
|
224
|
+
},
|
|
225
|
+
{
|
|
226
|
+
name: 'mediaType',
|
|
227
|
+
type: 'string',
|
|
228
|
+
description:
|
|
229
|
+
'The IANA media type of the image. Optional.',
|
|
230
|
+
isOptional: true,
|
|
231
|
+
},
|
|
232
|
+
],
|
|
233
|
+
},
|
|
234
|
+
{
|
|
235
|
+
type: 'FilePart',
|
|
236
|
+
parameters: [
|
|
237
|
+
{
|
|
238
|
+
name: 'type',
|
|
239
|
+
type: "'file'",
|
|
240
|
+
description: 'The type of the message part.',
|
|
241
|
+
},
|
|
242
|
+
{
|
|
243
|
+
name: 'data',
|
|
244
|
+
type: 'string | Uint8Array | Buffer | ArrayBuffer | URL',
|
|
245
|
+
description:
|
|
246
|
+
'The file content of the message part. String are either base64 encoded content, base64 data URLs, or http(s) URLs.',
|
|
247
|
+
},
|
|
248
|
+
{
|
|
249
|
+
name: 'mediaType',
|
|
250
|
+
type: 'string',
|
|
251
|
+
description: 'The IANA media type of the file.',
|
|
252
|
+
},
|
|
253
|
+
],
|
|
254
|
+
},
|
|
255
|
+
],
|
|
256
|
+
},
|
|
257
|
+
],
|
|
258
|
+
},
|
|
259
|
+
{
|
|
260
|
+
type: 'AssistantModelMessage',
|
|
261
|
+
parameters: [
|
|
262
|
+
{
|
|
263
|
+
name: 'role',
|
|
264
|
+
type: "'assistant'",
|
|
265
|
+
description: 'The role for the assistant message.',
|
|
266
|
+
},
|
|
267
|
+
{
|
|
268
|
+
name: 'content',
|
|
269
|
+
type: 'string | Array<TextPart | FilePart | ReasoningPart | ToolCallPart>',
|
|
270
|
+
description: 'The content of the message.',
|
|
271
|
+
properties: [
|
|
272
|
+
{
|
|
273
|
+
type: 'TextPart',
|
|
274
|
+
parameters: [
|
|
275
|
+
{
|
|
276
|
+
name: 'type',
|
|
277
|
+
type: "'text'",
|
|
278
|
+
description: 'The type of the message part.',
|
|
279
|
+
},
|
|
280
|
+
{
|
|
281
|
+
name: 'text',
|
|
282
|
+
type: 'string',
|
|
283
|
+
description: 'The text content of the message part.',
|
|
284
|
+
},
|
|
285
|
+
],
|
|
286
|
+
},
|
|
287
|
+
{
|
|
288
|
+
type: 'ReasoningPart',
|
|
289
|
+
parameters: [
|
|
290
|
+
{
|
|
291
|
+
name: 'type',
|
|
292
|
+
type: "'reasoning'",
|
|
293
|
+
description: 'The type of the message part.',
|
|
294
|
+
},
|
|
295
|
+
{
|
|
296
|
+
name: 'text',
|
|
297
|
+
type: 'string',
|
|
298
|
+
description: 'The reasoning text.',
|
|
299
|
+
},
|
|
300
|
+
],
|
|
301
|
+
},
|
|
302
|
+
{
|
|
303
|
+
type: 'FilePart',
|
|
304
|
+
parameters: [
|
|
305
|
+
{
|
|
306
|
+
name: 'type',
|
|
307
|
+
type: "'file'",
|
|
308
|
+
description: 'The type of the message part.',
|
|
309
|
+
},
|
|
310
|
+
{
|
|
311
|
+
name: 'data',
|
|
312
|
+
type: 'string | Uint8Array | Buffer | ArrayBuffer | URL',
|
|
313
|
+
description:
|
|
314
|
+
'The file content of the message part. String are either base64 encoded content, base64 data URLs, or http(s) URLs.',
|
|
315
|
+
},
|
|
316
|
+
{
|
|
317
|
+
name: 'mediaType',
|
|
318
|
+
type: 'string',
|
|
319
|
+
description: 'The IANA media type of the file.',
|
|
320
|
+
},
|
|
321
|
+
{
|
|
322
|
+
name: 'filename',
|
|
323
|
+
type: 'string',
|
|
324
|
+
description: 'The name of the file.',
|
|
325
|
+
isOptional: true,
|
|
326
|
+
},
|
|
327
|
+
],
|
|
328
|
+
},
|
|
329
|
+
{
|
|
330
|
+
type: 'ToolCallPart',
|
|
331
|
+
parameters: [
|
|
332
|
+
{
|
|
333
|
+
name: 'type',
|
|
334
|
+
type: "'tool-call'",
|
|
335
|
+
description: 'The type of the message part.',
|
|
336
|
+
},
|
|
337
|
+
{
|
|
338
|
+
name: 'toolCallId',
|
|
339
|
+
type: 'string',
|
|
340
|
+
description: 'The id of the tool call.',
|
|
341
|
+
},
|
|
342
|
+
{
|
|
343
|
+
name: 'toolName',
|
|
344
|
+
type: 'string',
|
|
345
|
+
description:
|
|
346
|
+
'The name of the tool, which typically would be the name of the function.',
|
|
347
|
+
},
|
|
348
|
+
{
|
|
349
|
+
name: 'args',
|
|
350
|
+
type: 'object based on zod schema',
|
|
351
|
+
description:
|
|
352
|
+
'Parameters generated by the model to be used by the tool.',
|
|
353
|
+
},
|
|
354
|
+
],
|
|
355
|
+
},
|
|
356
|
+
],
|
|
357
|
+
},
|
|
358
|
+
],
|
|
359
|
+
},
|
|
360
|
+
{
|
|
361
|
+
type: 'ToolModelMessage',
|
|
362
|
+
parameters: [
|
|
363
|
+
{
|
|
364
|
+
name: 'role',
|
|
365
|
+
type: "'tool'",
|
|
366
|
+
description: 'The role for the assistant message.',
|
|
367
|
+
},
|
|
368
|
+
{
|
|
369
|
+
name: 'content',
|
|
370
|
+
type: 'Array<ToolResultPart>',
|
|
371
|
+
description: 'The content of the message.',
|
|
372
|
+
properties: [
|
|
373
|
+
{
|
|
374
|
+
type: 'ToolResultPart',
|
|
375
|
+
parameters: [
|
|
376
|
+
{
|
|
377
|
+
name: 'type',
|
|
378
|
+
type: "'tool-result'",
|
|
379
|
+
description: 'The type of the message part.',
|
|
380
|
+
},
|
|
381
|
+
{
|
|
382
|
+
name: 'toolCallId',
|
|
383
|
+
type: 'string',
|
|
384
|
+
description:
|
|
385
|
+
'The id of the tool call the result corresponds to.',
|
|
386
|
+
},
|
|
387
|
+
{
|
|
388
|
+
name: 'toolName',
|
|
389
|
+
type: 'string',
|
|
390
|
+
description:
|
|
391
|
+
'The name of the tool the result corresponds to.',
|
|
392
|
+
},
|
|
393
|
+
{
|
|
394
|
+
name: 'result',
|
|
395
|
+
type: 'unknown',
|
|
396
|
+
description:
|
|
397
|
+
'The result returned by the tool after execution.',
|
|
398
|
+
},
|
|
399
|
+
{
|
|
400
|
+
name: 'isError',
|
|
401
|
+
type: 'boolean',
|
|
402
|
+
isOptional: true,
|
|
403
|
+
description:
|
|
404
|
+
'Whether the result is an error or an error message.',
|
|
405
|
+
},
|
|
406
|
+
],
|
|
407
|
+
},
|
|
408
|
+
],
|
|
409
|
+
},
|
|
410
|
+
],
|
|
411
|
+
},
|
|
412
|
+
],
|
|
413
|
+
},
|
|
414
|
+
{
|
|
415
|
+
name: 'maxOutputTokens',
|
|
416
|
+
type: 'number',
|
|
417
|
+
isOptional: true,
|
|
418
|
+
description: 'Maximum number of tokens to generate.',
|
|
419
|
+
},
|
|
420
|
+
{
|
|
421
|
+
name: 'temperature',
|
|
422
|
+
type: 'number',
|
|
423
|
+
isOptional: true,
|
|
424
|
+
description:
|
|
425
|
+
'Temperature setting. The value is passed through to the provider. The range depends on the provider and model. It is recommended to set either `temperature` or `topP`, but not both.',
|
|
426
|
+
},
|
|
427
|
+
{
|
|
428
|
+
name: 'topP',
|
|
429
|
+
type: 'number',
|
|
430
|
+
isOptional: true,
|
|
431
|
+
description:
|
|
432
|
+
'Nucleus sampling. The value is passed through to the provider. The range depends on the provider and model. It is recommended to set either `temperature` or `topP`, but not both.',
|
|
433
|
+
},
|
|
434
|
+
{
|
|
435
|
+
name: 'topK',
|
|
436
|
+
type: 'number',
|
|
437
|
+
isOptional: true,
|
|
438
|
+
description:
|
|
439
|
+
'Only sample from the top K options for each subsequent token. Used to remove "long tail" low probability responses. Recommended for advanced use cases only. You usually only need to use temperature.',
|
|
440
|
+
},
|
|
441
|
+
{
|
|
442
|
+
name: 'presencePenalty',
|
|
443
|
+
type: 'number',
|
|
444
|
+
isOptional: true,
|
|
445
|
+
description:
|
|
446
|
+
'Presence penalty setting. It affects the likelihood of the model to repeat information that is already in the prompt. The value is passed through to the provider. The range depends on the provider and model.',
|
|
447
|
+
},
|
|
448
|
+
{
|
|
449
|
+
name: 'frequencyPenalty',
|
|
450
|
+
type: 'number',
|
|
451
|
+
isOptional: true,
|
|
452
|
+
description:
|
|
453
|
+
'Frequency penalty setting. It affects the likelihood of the model to repeatedly use the same words or phrases. The value is passed through to the provider. The range depends on the provider and model.',
|
|
454
|
+
},
|
|
455
|
+
{
|
|
456
|
+
name: 'seed',
|
|
457
|
+
type: 'number',
|
|
458
|
+
isOptional: true,
|
|
459
|
+
description:
|
|
460
|
+
'The seed (integer) to use for random sampling. If set and supported by the model, calls will generate deterministic results.',
|
|
461
|
+
},
|
|
462
|
+
{
|
|
463
|
+
name: 'maxRetries',
|
|
464
|
+
type: 'number',
|
|
465
|
+
isOptional: true,
|
|
466
|
+
description:
|
|
467
|
+
'Maximum number of retries. Set to 0 to disable retries. Default: 2.',
|
|
468
|
+
},
|
|
469
|
+
{
|
|
470
|
+
name: 'abortSignal',
|
|
471
|
+
type: 'AbortSignal',
|
|
472
|
+
isOptional: true,
|
|
473
|
+
description:
|
|
474
|
+
'An optional abort signal that can be used to cancel the call.',
|
|
475
|
+
},
|
|
476
|
+
{
|
|
477
|
+
name: 'headers',
|
|
478
|
+
type: 'Record<string, string>',
|
|
479
|
+
isOptional: true,
|
|
480
|
+
description:
|
|
481
|
+
'Additional HTTP headers to be sent with the request. Only applicable for HTTP-based providers.',
|
|
482
|
+
},
|
|
483
|
+
{
|
|
484
|
+
name: 'experimental_repairText',
|
|
485
|
+
type: '(options: RepairTextOptions) => Promise<string>',
|
|
486
|
+
isOptional: true,
|
|
487
|
+
description:
|
|
488
|
+
'A function that attempts to repair the raw output of the model to enable JSON parsing. Should return the repaired text or null if the text cannot be repaired.',
|
|
489
|
+
properties: [
|
|
490
|
+
{
|
|
491
|
+
type: 'RepairTextOptions',
|
|
492
|
+
parameters: [
|
|
493
|
+
{
|
|
494
|
+
name: 'text',
|
|
495
|
+
type: 'string',
|
|
496
|
+
description: 'The text that was generated by the model.',
|
|
497
|
+
},
|
|
498
|
+
{
|
|
499
|
+
name: 'error',
|
|
500
|
+
type: 'JSONParseError | TypeValidationError',
|
|
501
|
+
description: 'The error that occurred while parsing the text.',
|
|
502
|
+
},
|
|
503
|
+
],
|
|
504
|
+
},
|
|
505
|
+
],
|
|
506
|
+
},
|
|
507
|
+
{
|
|
508
|
+
name: 'experimental_download',
|
|
509
|
+
type: '(requestedDownloads: Array<{ url: URL; isUrlSupportedByModel: boolean }>) => Promise<Array<null | { data: Uint8Array; mediaType?: string }>>',
|
|
510
|
+
isOptional: true,
|
|
511
|
+
description:
|
|
512
|
+
'Custom download function to control how URLs are fetched when they appear in prompts. By default, files are downloaded if the model does not support the URL for the given media type. Experimental feature. Return null to pass the URL directly to the model (when supported), or return downloaded content with data and media type.',
|
|
513
|
+
},
|
|
514
|
+
{
|
|
515
|
+
name: 'experimental_telemetry',
|
|
516
|
+
type: 'TelemetrySettings',
|
|
517
|
+
isOptional: true,
|
|
518
|
+
description: 'Telemetry configuration. Experimental feature.',
|
|
519
|
+
properties: [
|
|
520
|
+
{
|
|
521
|
+
type: 'TelemetrySettings',
|
|
522
|
+
parameters: [
|
|
523
|
+
{
|
|
524
|
+
name: 'isEnabled',
|
|
525
|
+
type: 'boolean',
|
|
526
|
+
isOptional: true,
|
|
527
|
+
description:
|
|
528
|
+
'Enable or disable telemetry. Disabled by default while experimental.',
|
|
529
|
+
},
|
|
530
|
+
{
|
|
531
|
+
name: 'recordInputs',
|
|
532
|
+
type: 'boolean',
|
|
533
|
+
isOptional: true,
|
|
534
|
+
description:
|
|
535
|
+
'Enable or disable input recording. Enabled by default.',
|
|
536
|
+
},
|
|
537
|
+
{
|
|
538
|
+
name: 'recordOutputs',
|
|
539
|
+
type: 'boolean',
|
|
540
|
+
isOptional: true,
|
|
541
|
+
description:
|
|
542
|
+
'Enable or disable output recording. Enabled by default.',
|
|
543
|
+
},
|
|
544
|
+
{
|
|
545
|
+
name: 'functionId',
|
|
546
|
+
type: 'string',
|
|
547
|
+
isOptional: true,
|
|
548
|
+
description:
|
|
549
|
+
'Identifier for this function. Used to group telemetry data by function.',
|
|
550
|
+
},
|
|
551
|
+
{
|
|
552
|
+
name: 'metadata',
|
|
553
|
+
isOptional: true,
|
|
554
|
+
type: 'Record<string, string | number | boolean | Array<null | undefined | string> | Array<null | undefined | number> | Array<null | undefined | boolean>>',
|
|
555
|
+
description:
|
|
556
|
+
'Additional information to include in the telemetry data.',
|
|
557
|
+
},
|
|
558
|
+
],
|
|
559
|
+
},
|
|
560
|
+
],
|
|
561
|
+
},
|
|
562
|
+
{
|
|
563
|
+
name: 'providerOptions',
|
|
564
|
+
type: 'Record<string,JSONObject> | undefined',
|
|
565
|
+
isOptional: true,
|
|
566
|
+
description:
|
|
567
|
+
'Provider-specific options. The outer key is the provider name. The inner values are the metadata. Details depend on the provider.',
|
|
568
|
+
},
|
|
569
|
+
]}
|
|
570
|
+
/>
|
|
571
|
+
|
|
572
|
+
### Returns
|
|
573
|
+
|
|
574
|
+
<PropertiesTable
|
|
575
|
+
content={[
|
|
576
|
+
{
|
|
577
|
+
name: 'object',
|
|
578
|
+
type: 'based on the schema',
|
|
579
|
+
description:
|
|
580
|
+
'The generated object, validated by the schema (if it supports validation).',
|
|
581
|
+
},
|
|
582
|
+
{
|
|
583
|
+
name: 'finishReason',
|
|
584
|
+
type: "'stop' | 'length' | 'content-filter' | 'tool-calls' | 'error' | 'other'",
|
|
585
|
+
description: 'The reason the model finished generating the text.',
|
|
586
|
+
},
|
|
587
|
+
{
|
|
588
|
+
name: 'usage',
|
|
589
|
+
type: 'LanguageModelUsage',
|
|
590
|
+
description: 'The token usage of the generated text.',
|
|
591
|
+
properties: [
|
|
592
|
+
{
|
|
593
|
+
type: 'LanguageModelUsage',
|
|
594
|
+
parameters: [
|
|
595
|
+
{
|
|
596
|
+
name: 'inputTokens',
|
|
597
|
+
type: 'number | undefined',
|
|
598
|
+
description: 'The total number of input (prompt) tokens used.',
|
|
599
|
+
},
|
|
600
|
+
{
|
|
601
|
+
name: 'inputTokenDetails',
|
|
602
|
+
type: 'LanguageModelInputTokenDetails',
|
|
603
|
+
description:
|
|
604
|
+
'Detailed information about the input (prompt) tokens. See also: cached tokens and non-cached tokens.',
|
|
605
|
+
properties: [
|
|
606
|
+
{
|
|
607
|
+
type: 'LanguageModelInputTokenDetails',
|
|
608
|
+
parameters: [
|
|
609
|
+
{
|
|
610
|
+
name: 'noCacheTokens',
|
|
611
|
+
type: 'number | undefined',
|
|
612
|
+
description:
|
|
613
|
+
'The number of non-cached input (prompt) tokens used.',
|
|
614
|
+
},
|
|
615
|
+
{
|
|
616
|
+
name: 'cacheReadTokens',
|
|
617
|
+
type: 'number | undefined',
|
|
618
|
+
description:
|
|
619
|
+
'The number of cached input (prompt) tokens read.',
|
|
620
|
+
},
|
|
621
|
+
{
|
|
622
|
+
name: 'cacheWriteTokens',
|
|
623
|
+
type: 'number | undefined',
|
|
624
|
+
description:
|
|
625
|
+
'The number of cached input (prompt) tokens written.',
|
|
626
|
+
},
|
|
627
|
+
],
|
|
628
|
+
},
|
|
629
|
+
],
|
|
630
|
+
},
|
|
631
|
+
{
|
|
632
|
+
name: 'outputTokens',
|
|
633
|
+
type: 'number | undefined',
|
|
634
|
+
description:
|
|
635
|
+
'The number of total output (completion) tokens used.',
|
|
636
|
+
},
|
|
637
|
+
{
|
|
638
|
+
name: 'outputTokenDetails',
|
|
639
|
+
type: 'LanguageModelOutputTokenDetails',
|
|
640
|
+
description:
|
|
641
|
+
'Detailed information about the output (completion) tokens.',
|
|
642
|
+
properties: [
|
|
643
|
+
{
|
|
644
|
+
type: 'LanguageModelOutputTokenDetails',
|
|
645
|
+
parameters: [
|
|
646
|
+
{
|
|
647
|
+
name: 'textTokens',
|
|
648
|
+
type: 'number | undefined',
|
|
649
|
+
description: 'The number of text tokens used.',
|
|
650
|
+
},
|
|
651
|
+
{
|
|
652
|
+
name: 'reasoningTokens',
|
|
653
|
+
type: 'number | undefined',
|
|
654
|
+
description: 'The number of reasoning tokens used.',
|
|
655
|
+
},
|
|
656
|
+
],
|
|
657
|
+
},
|
|
658
|
+
],
|
|
659
|
+
},
|
|
660
|
+
{
|
|
661
|
+
name: 'totalTokens',
|
|
662
|
+
type: 'number | undefined',
|
|
663
|
+
description: 'The total number of tokens used.',
|
|
664
|
+
},
|
|
665
|
+
{
|
|
666
|
+
name: 'raw',
|
|
667
|
+
type: 'object | undefined',
|
|
668
|
+
isOptional: true,
|
|
669
|
+
description:
|
|
670
|
+
"Raw usage information from the provider. This is the provider's original usage information and may include additional fields.",
|
|
671
|
+
},
|
|
672
|
+
],
|
|
673
|
+
},
|
|
674
|
+
],
|
|
675
|
+
},
|
|
676
|
+
{
|
|
677
|
+
name: 'request',
|
|
678
|
+
type: 'LanguageModelRequestMetadata',
|
|
679
|
+
isOptional: true,
|
|
680
|
+
description: 'Request metadata.',
|
|
681
|
+
properties: [
|
|
682
|
+
{
|
|
683
|
+
type: 'LanguageModelRequestMetadata',
|
|
684
|
+
parameters: [
|
|
685
|
+
{
|
|
686
|
+
name: 'body',
|
|
687
|
+
type: 'string',
|
|
688
|
+
description:
|
|
689
|
+
'Raw request HTTP body that was sent to the provider API as a string (JSON should be stringified).',
|
|
690
|
+
},
|
|
691
|
+
],
|
|
692
|
+
},
|
|
693
|
+
],
|
|
694
|
+
},
|
|
695
|
+
{
|
|
696
|
+
name: 'response',
|
|
697
|
+
type: 'LanguageModelResponseMetadata',
|
|
698
|
+
isOptional: true,
|
|
699
|
+
description: 'Response metadata.',
|
|
700
|
+
properties: [
|
|
701
|
+
{
|
|
702
|
+
type: 'LanguageModelResponseMetadata',
|
|
703
|
+
parameters: [
|
|
704
|
+
{
|
|
705
|
+
name: 'id',
|
|
706
|
+
type: 'string',
|
|
707
|
+
description:
|
|
708
|
+
'The response identifier. The AI SDK uses the ID from the provider response when available, and generates an ID otherwise.',
|
|
709
|
+
},
|
|
710
|
+
{
|
|
711
|
+
name: 'modelId',
|
|
712
|
+
type: 'string',
|
|
713
|
+
description:
|
|
714
|
+
'The model that was used to generate the response. The AI SDK uses the response model from the provider response when available, and the model from the function call otherwise.',
|
|
715
|
+
},
|
|
716
|
+
{
|
|
717
|
+
name: 'timestamp',
|
|
718
|
+
type: 'Date',
|
|
719
|
+
description:
|
|
720
|
+
'The timestamp of the response. The AI SDK uses the response timestamp from the provider response when available, and creates a timestamp otherwise.',
|
|
721
|
+
},
|
|
722
|
+
{
|
|
723
|
+
name: 'headers',
|
|
724
|
+
isOptional: true,
|
|
725
|
+
type: 'Record<string, string>',
|
|
726
|
+
description: 'Optional response headers.',
|
|
727
|
+
},
|
|
728
|
+
{
|
|
729
|
+
name: 'body',
|
|
730
|
+
isOptional: true,
|
|
731
|
+
type: 'unknown',
|
|
732
|
+
description: 'Optional response body.',
|
|
733
|
+
},
|
|
734
|
+
],
|
|
735
|
+
},
|
|
736
|
+
],
|
|
737
|
+
},
|
|
738
|
+
{
|
|
739
|
+
name: 'reasoning',
|
|
740
|
+
type: 'string | undefined',
|
|
741
|
+
description:
|
|
742
|
+
'The reasoning that was used to generate the object. Concatenated from all reasoning parts.',
|
|
743
|
+
},
|
|
744
|
+
{
|
|
745
|
+
name: 'warnings',
|
|
746
|
+
type: 'Warning[] | undefined',
|
|
747
|
+
description:
|
|
748
|
+
'Warnings from the model provider (e.g. unsupported settings).',
|
|
749
|
+
},
|
|
750
|
+
{
|
|
751
|
+
name: 'providerMetadata',
|
|
752
|
+
type: 'ProviderMetadata | undefined',
|
|
753
|
+
description:
|
|
754
|
+
'Optional metadata from the provider. The outer key is the provider name. The inner values are the metadata. Details depend on the provider.',
|
|
755
|
+
},
|
|
756
|
+
{
|
|
757
|
+
name: 'toJsonResponse',
|
|
758
|
+
type: '(init?: ResponseInit) => Response',
|
|
759
|
+
description:
|
|
760
|
+
'Converts the object to a JSON response. The response will have a status code of 200 and a content type of `application/json; charset=utf-8`.',
|
|
761
|
+
},
|
|
762
|
+
]}
|
|
763
|
+
/>
|
|
764
|
+
|
|
765
|
+
## More Examples
|
|
766
|
+
|
|
767
|
+
<ExampleLinks
|
|
768
|
+
examples={[
|
|
769
|
+
{
|
|
770
|
+
title:
|
|
771
|
+
'Learn to generate structured data using a language model in Next.js',
|
|
772
|
+
link: '/examples/next-app/basics/generating-object',
|
|
773
|
+
},
|
|
774
|
+
{
|
|
775
|
+
title:
|
|
776
|
+
'Learn to generate structured data using a language model in Node.js',
|
|
777
|
+
link: '/examples/node/generating-structured-data/generate-object',
|
|
778
|
+
},
|
|
779
|
+
]}
|
|
780
|
+
/>
|