Skip to main content

Recipes

Each recipe is one task, one complete program and links to the guide and reference for more depth. Every program lives in examples/recipes, is built by CI, and compiles without API keys. Set the keys a recipe names to run it.

RecipeTask
Serve a useChat frontendServe an endpoint that the useChat hook from @ai-sdk/react can talk to.
Ask before running a toolLet the model request a tool, but run it only after the user says yes.
Use tools from an MCP serverCall the tools of a Model Context Protocol (MCP) server from GenerateText.
Get typed data from a modelGet a Go struct back from a model, not free text.
Switch providersRun the same code on different providers, chosen by configuration.
Use Claude with reasoningHave Claude think before it answers, and read what it thought.
Run Claude Code or CodexHand a coding task to Claude Code or Codex and read what it changed.
Retrieve context with embeddingsAnswer questions from your own documents.
Handle rate limits and retriesMake calls resilient to 429 and 5xx responses, and fail clearly when they are not.
Test code that calls a modelWrite fast, deterministic tests for code that calls a language model.
Run a tool loop with an agentLet a model call your Go functions until it has an answer.
Stream text as it arrivesPrint a model's answer while it is still being written.

Reference app​

For a full application that combines several of these recipes, see the Build a chat app guides and the Shipyard demo.