Examples · anthropic · 45 of 339
batch
The Anthropic API beyond one agent turn, from Tin: count tokens, list models, send a Message Batch, wait for it and read the results.
tin run examples/anthropic/batch.tin// The Anthropic API beyond one agent turn, from Tin: count tokens, list models, send a Message Batch,
// wait for it and read the results. Needs ANTHROPIC_API_KEY.
import "std/anthropic"
fn main() {
let c = anthropic.fromEnv()
print("tokens: {c.countText("claude-haiku-4-5", "", "Hello, Claude").unwrap()}")
for m in c.models().unwrap() { print("{m.id} thinking={m.supports("thinking")}") }
let questions = ["What is 2 + 2?", "Name a prime above 100."]
var reqs: Json[] = []
for i in 0..questions.len { reqs.push(anthropic.batchText("q{i}", "claude-haiku-4-5", 200, questions[i])) }
let b = c.createBatch(reqs).unwrap()
let done = c.waitBatch(b.id, 30s, 120).unwrap()
if !done.ended() {
print("still running: {done.processing} left")
return
}
for r in c.batchResults(b.id).unwrap() { print("{r.customId}: {r.kind} {r.text}") }
}