Examples

Recipes for common patterns

Real, copy-paste snippets that show how usecrow works across runtimes and use cases.

Stream to the terminal

The minimal streaming loop, no framework required.

stream.ts
1const stream = await crow.send("Write a haiku about crows")
2
3for await (const chunk of stream) {
4 process.stdout.write(chunk.text)
5}

Tool calling with Zod

Let an agent call your typed functions safely.

tools.ts
1const getWeather = crow.tool({
2 name: "getWeather",
3 schema: z.object({ city: z.string() }),
4 run: async ({ city }) => weather.lookup(city),
5})
6
7await crow.send("What's the weather in Tokyo?", {
8 tools: { getWeather },
9})

Fork a conversation

Branch a thread to explore alternate responses.

fork.ts
1const thread = await crow.threads.create()
2await crow.send("Draft a reply", { thread: thread.id })
3
4const alt = await crow.threads.fork(thread.id)
5await crow.send("Make it more formal", { thread: alt.id })

Edge runtime handler

Deploy the client inside an edge function.

route.ts
1export const runtime = "edge"
2
3export async function POST(req: Request) {
4 const { message } = await req.json()
5 const stream = await crow.send(message)
6 return new Response(stream.toReadable())
7}