docs(ST-qfpqpxzy): worker-quota-probe.sh + uitgebreide pre-flight runbook + architectuurdoc
- scripts/worker-quota-probe.sh: curl-probe die rate-limit-headers parset en { remaining, limit, pct, reset_at_iso } JSON retourneert
- mcp-integration.md: pre-flight sectie uitgebreid met bash-script voorbeeld, retry-strategie (sleep tot reset+5s), bekende beperking
- claude-question-channel.md: M13 quota-gate flow diagram + pre-flight loop uitleg
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
parent
661601e833
commit
bc6936159d
3 changed files with 96 additions and 26 deletions
44
scripts/worker-quota-probe.sh
Executable file
44
scripts/worker-quota-probe.sh
Executable file
|
|
@ -0,0 +1,44 @@
|
|||
#!/usr/bin/env bash
|
||||
# worker-quota-probe.sh — Probe Claude API rate-limit headers en output JSON.
|
||||
#
|
||||
# Vereist: ANTHROPIC_API_KEY env-var.
|
||||
# Output: { "remaining": N, "limit": N, "pct": N, "reset_at_iso": "..." }
|
||||
# Exit 0 bij succes, exit 1 bij fout (geen API key, curl-fout, parse-fout).
|
||||
|
||||
set -euo pipefail
|
||||
|
||||
if [ -z "${ANTHROPIC_API_KEY:-}" ]; then
|
||||
echo '{"error":"ANTHROPIC_API_KEY not set"}' >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
HEADERS_FILE=$(mktemp /tmp/quota-probe-headers.XXXXXX)
|
||||
trap 'rm -f "$HEADERS_FILE"' EXIT
|
||||
|
||||
# Minimale API-aanroep (1 token) om rate-limit-headers te lezen.
|
||||
HTTP_STATUS=$(curl -s -w "%{http_code}" -D "$HEADERS_FILE" -o /dev/null \
|
||||
-X POST https://api.anthropic.com/v1/messages \
|
||||
-H "x-api-key: $ANTHROPIC_API_KEY" \
|
||||
-H "anthropic-version: 2023-06-01" \
|
||||
-H "content-type: application/json" \
|
||||
-d '{"model":"claude-haiku-4-5-20251001","max_tokens":1,"messages":[{"role":"user","content":"."}]}')
|
||||
|
||||
if [ "$HTTP_STATUS" -ge 500 ]; then
|
||||
echo "{\"error\":\"API returned HTTP $HTTP_STATUS\"}" >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Parse headers (case-insensitive grep)
|
||||
REMAINING=$(grep -i 'anthropic-ratelimit-tokens-remaining:' "$HEADERS_FILE" | awk '{print $2}' | tr -d '\r' || true)
|
||||
LIMIT=$(grep -i 'anthropic-ratelimit-tokens-limit:' "$HEADERS_FILE" | awk '{print $2}' | tr -d '\r' || true)
|
||||
RESET=$(grep -i 'anthropic-ratelimit-tokens-reset:' "$HEADERS_FILE" | awk '{print $2}' | tr -d '\r' || true)
|
||||
|
||||
if [ -z "$REMAINING" ] || [ -z "$LIMIT" ] || [ "$LIMIT" -eq 0 ] 2>/dev/null; then
|
||||
echo '{"error":"rate-limit headers not present in response"}' >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
PCT=$(( REMAINING * 100 / LIMIT ))
|
||||
|
||||
printf '{"remaining":%s,"limit":%s,"pct":%s,"reset_at_iso":"%s"}\n' \
|
||||
"$REMAINING" "$LIMIT" "$PCT" "$RESET"
|
||||
Loading…
Add table
Add a link
Reference in a new issue