SPB Git forge

spb/doc-api

Public
2commits 1branches 0releases
15.7 MBsize
maindefault branch
14 days agolast push
Python 88.3% TypeScript 7.6% Shell 4.1%
1.2 KB · 19 lines shellscript
Raw Blame History
1#!/usr/bin/env bash2# Structured outputs: output_config.format {type:"json_schema", schema} — the text block is guaranteed-valid JSON.3# STATUS: LIVE_VERIFIED 2026-09-18 (claude-haiku-4-5-20251001): {"name":"Ada","age":36,"city":"Lyon"} (~$0.0003).4# Run: bash examples/anthropic/structured-output/json_schema.sh5set -eo pipefail6cd "$(dirname "$0")/../../.." && source scripts/lib.sh7OUTF="$(mktemp)"; trap 'rm -f "$OUTF"' EXIT8# `ant` sets ANT_STATUS; calling it inside $(...) would lose it, so write the body to a file instead.9call() { ant "$@" > "$OUTF"; OUT="$(cat "$OUTF")"; }10MODEL="${ANTHROPIC_MODEL:-claude-haiku-4-5-20251001}"11call POST /v1/messages -d "$(jq -n --arg m "$MODEL" '{model:$m, max_tokens:100,12  output_config:{format:{type:"json_schema", schema:{type:"object",13    properties:{name:{type:"string"}, age:{type:"integer"}, city:{type:"string"}},14    required:["name","age","city"], additionalProperties:false}}},15  messages:[{role:"user", content:"Ada is 36 and lives in Lyon. Extract the person."}]}')"16echo "HTTP $ANT_STATUS"17echo "$OUT" | jq -r '.content[0].text' | jq -c .   # second jq proves it parses18log_request anthropic POST /v1/messages "$ANT_STATUS" 0.0003 "example structured-output/json_schema.sh $MODEL"19