#!/usr/bin/env bash # Admin API read-only probes. # STATUS: GET /v1/organizations/me → LIVE_VERIFIED 2026-09-18 with the REGULAR key (HTTP 200). # usage_report/messages, cost_report, usage_report/claude_code → ACCOUNT_RESTRICTED (401 "The Admin API requires an # Admin API key or an organization-scoped API key."). Set ANTHROPIC_ADMIN_KEY in .env to run them for real. # Usage: source scripts/lib.sh && bash examples/anthropic/admin/org_me_and_usage_report.sh (requires jq) set -uo pipefail cd "$(dirname "$0")/../../.." # shellcheck disable=SC1091 source scripts/lib.sh # 1. organization info — works with any key kind ant GET /v1/organizations/me | jq -c .; log_request anthropic GET /v1/organizations/me "$ANT_STATUS" 0 "admin example org me" # 2. Admin-key endpoints (read-only). Use the admin key when present, else show the 401 honestly. KEY="${ANTHROPIC_ADMIN_KEY:-$ANTHROPIC_API_KEY}" adm() { # adm PATH local out; out="$(mktemp)" ADM_STATUS=$(curl -sS -o "$out" -w '%{http_code}' "https://api.anthropic.com$1" -H "x-api-key: $KEY" -H "anthropic-version: $ANTHROPIC_VERSION") cat "$out"; rm -f "$out" } start=$(date -u -v-7d +%FT00:00:00Z 2>/dev/null || date -u -d '7 days ago' +%FT00:00:00Z) day=$(date -u -v-1d +%F 2>/dev/null || date -u -d 'yesterday' +%F) echo "--- usage_report/messages (daily, by model)"; adm "/v1/organizations/usage_report/messages?starting_at=$start&bucket_width=1d&group_by[]=model" | mask | jq -c '.' | cut -c1-400 log_request anthropic GET /v1/organizations/usage_report/messages "$ADM_STATUS" 0 "admin example usage report" echo "--- cost_report (daily, by workspace)"; adm "/v1/organizations/cost_report?starting_at=$start&group_by[]=workspace_id" | mask | jq -c '.' | cut -c1-400 log_request anthropic GET /v1/organizations/cost_report "$ADM_STATUS" 0 "admin example cost report" echo "--- usage_report/claude_code ($day)"; adm "/v1/organizations/usage_report/claude_code?starting_at=$day&limit=5" | mask | jq -c '.' | cut -c1-400 log_request anthropic GET /v1/organizations/usage_report/claude_code "$ADM_STATUS" 0 "admin example claude code analytics"