Cookbook

Run the example path from first text call to Studio and integrations.

The cookbook is the runnable companion to the guides. Use it when you want to verify a concept from the command line before adapting it into product code.

Each level introduces one layer at a time:

LevelFocus
BasicsText calls, chat history, static context, streaming, and ReadableStream output
ToolsTool calls, streamed tool events, hooks, concurrency, conditional tools, application state, guarded tools, and dynamic tool selection
Structured outputExtraction, output schemas, context, retries, and extraction with history
Providers and multimodalProvider adapters, model capabilities, model listing, reasoning streams, attachments, image generation, audio generation, and transcription
PipelinesStep transforms, composition, named parallel branches, batching, agents, extraction, and richer workflows
RetrievalEmbeddings, vector search, metadata filters, RAG context, document loaders, vector stores, and embedding provider variants
Multi-agentBasic agent-tools, pipeline-backed parallel specialists, streaming agent-tools, and event stores
EvalsDeterministic metrics, semantic similarity, custom metrics, agent eval targets, and LLM judge/score
StudioSingle-agent, multi-agent, and subagent runners, tool approvals, questions, and Knowledge inspection
IntegrationsMCP tools, local skills, Langfuse tracing, and Langfuse eval reporting

1. Install Dependencies

From the repository root:

pnpm install

Create a local .env file for examples that call provider APIs:

OPENAI_API_KEY=...
OPENAI_BASEURL=...
ANTHROPIC_API_KEY=...
GEMINI_API_KEY=...
MISTRAL_API_KEY=...

Anvia clients still receive credentials explicitly in code. The cookbook uses dotenv only as a local configuration source.

2. Run the First Example

pnpm cookbook:basics:01

That runs examples/cookbook/01_basics/01-text-call.ts.

3. Follow the Path

Run the default example for each level:

pnpm cookbook:basics
pnpm cookbook:tools
pnpm cookbook:structured-output
pnpm cookbook:providers
pnpm cookbook:pipelines
pnpm cookbook:retrieval
pnpm cookbook:multi-agent
pnpm cookbook:evals
pnpm cookbook:studio
pnpm cookbook:integrations

Numbered scripts are available when you want to step through a level in order:

pnpm cookbook:tools:01
pnpm cookbook:pipelines:04
pnpm cookbook:retrieval:05
pnpm cookbook:studio:06
pnpm cookbook:integrations:04

Legacy names such as cookbook:basic:05, cookbook:intermediate:14, cookbook:pipeline:04, cookbook:rag:05, and cookbook:multimodal:03 remain available as aliases.

4. Use Chroma Examples

Start ChromaDB before running the Chroma-backed RAG examples:

docker compose -f examples/cookbook/compose.cookbook.yml up -d
pnpm cookbook:retrieval:05
pnpm cookbook:retrieval:06
pnpm cookbook:retrieval:07
pnpm cookbook:retrieval:08

Use the in-memory and Transformers examples when you do not need a separate vector database.

5. Map Examples to Guides

GoalCookbookGuide
Add a tooltools:01Add Tools
Return structured datastructured-output:01, structured-output:02Structured Output
Inspect model capabilitiesproviders:03Provider Clients and Models
List provider modelsproviders:10Model Listing
Stream agent eventstools:02Streaming Events
Render reasoning summariesproviders:04Streaming Events
Select dynamic toolstools:09Tool Sets
Add approval behaviortools:08, studio:03Human in the Loop
Add retrievalretrieval:01 through retrieval:06Add Retrieval
Run evalsevals:01 through evals:05, integrations:04Evals
Generate or transcribe mediaproviders:07 through providers:09Image Generation
Inspect locally in Studiostudio:01, studio:05, studio:06Run Studio

Before changing public APIs, add or update a cookbook example so behavior is easy to verify from the command line.