Workers AI can be used with the AI SDK ↗ for JavaScript and TypeScript codebases.
Install the workers-ai-provider
provider ↗:
Then, add an AI binding in your Workers project wrangler.toml
file:
The AI SDK can be configured to work with any AI model.
Once you have selected your model, you can generate text from a given prompt.
For longer responses, consider streaming responses to provide as the generation completes.
Generate Structured Objects
You can provide a Zod schema to generate a structured JSON response.
Thank you for helping improve Cloudflare's documentation!