# Recipes

> Short, complete programs for common tasks with the Go AI SDK, each with a runnable example in the repository.

Canonical URL: https://goaisdk.com/docs/recipes/
Documentation index: https://goaisdk.com/llms.txt

Each recipe is one task, one complete program and links to the guide and reference for more depth. Every program lives in [`examples/recipes`](https://github.com/digitallysavvy/go-ai/tree/main/examples/recipes), is built by CI, and compiles without API keys. Set the keys a recipe names to run it.

| Recipe | Task |
| --- | --- |
| [Serve a useChat frontend](https://goaisdk.com/docs/recipes/usechat-backend.md) | Serve an endpoint that the `useChat` hook from `@ai-sdk/react` can talk to. |
| [Ask before running a tool](https://goaisdk.com/docs/recipes/tool-approval.md) | Let the model request a tool, but run it only after the user says yes. |
| [Use tools from an MCP server](https://goaisdk.com/docs/recipes/mcp-tools.md) | Call the tools of a Model Context Protocol (MCP) server from `GenerateText`. |
| [Get typed data from a model](https://goaisdk.com/docs/recipes/structured-output.md) | Get a Go struct back from a model, not free text. |
| [Switch providers](https://goaisdk.com/docs/recipes/switch-providers.md) | Run the same code on different providers, chosen by configuration. |
| [Use Claude with reasoning](https://goaisdk.com/docs/recipes/claude-reasoning.md) | Have Claude think before it answers, and read what it thought. |
| [Run Claude Code or Codex](https://goaisdk.com/docs/recipes/harness-coding-agent.md) | Hand a coding task to Claude Code or Codex and read what it changed. |
| [Retrieve context with embeddings](https://goaisdk.com/docs/recipes/rag-embeddings.md) | Answer questions from your own documents. |
| [Handle rate limits and retries](https://goaisdk.com/docs/recipes/rate-limits-retries.md) | Make calls resilient to 429 and 5xx responses, and fail clearly when they are not. |
| [Test code that calls a model](https://goaisdk.com/docs/recipes/mock-model-tests.md) | Write fast, deterministic tests for code that calls a language model. |
| [Run a tool loop with an agent](https://goaisdk.com/docs/recipes/agent-with-tools.md) | Let a model call your Go functions until it has an answer. |
| [Stream text as it arrives](https://goaisdk.com/docs/recipes/stream-text.md) | Print 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](https://goaisdk.com/docs/build-a-chat-app.md) guides and the [Shipyard demo](https://github.com/digitallysavvy/go-ai-demo).
