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%
2.1 KB · 31 lines shellscript
Raw Blame History
1#!/usr/bin/env bash2# Admin API read-only probes.3# STATUS: GET /v1/organizations/me → LIVE_VERIFIED 2026-09-18 with the REGULAR key (HTTP 200).4#         usage_report/messages, cost_report, usage_report/claude_code → ACCOUNT_RESTRICTED (401 "The Admin API requires an5#         Admin API key or an organization-scoped API key."). Set ANTHROPIC_ADMIN_KEY in .env to run them for real.6# Usage: source scripts/lib.sh && bash examples/anthropic/admin/org_me_and_usage_report.sh   (requires jq)7set -uo pipefail8cd "$(dirname "$0")/../../.."9# shellcheck disable=SC109110source scripts/lib.sh1112# 1. organization info — works with any key kind13ant GET /v1/organizations/me | jq -c .; log_request anthropic GET /v1/organizations/me "$ANT_STATUS" 0 "admin example org me"1415# 2. Admin-key endpoints (read-only). Use the admin key when present, else show the 401 honestly.16KEY="${ANTHROPIC_ADMIN_KEY:-$ANTHROPIC_API_KEY}"17adm() { # adm PATH18  local out; out="$(mktemp)"19  ADM_STATUS=$(curl -sS -o "$out" -w '%{http_code}' "https://api.anthropic.com$1" -H "x-api-key: $KEY" -H "anthropic-version: $ANTHROPIC_VERSION")20  cat "$out"; rm -f "$out"21}22start=$(date -u -v-7d +%FT00:00:00Z 2>/dev/null || date -u -d '7 days ago' +%FT00:00:00Z)23day=$(date -u -v-1d +%F 2>/dev/null || date -u -d 'yesterday' +%F)2425echo "--- 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-40026log_request anthropic GET /v1/organizations/usage_report/messages "$ADM_STATUS" 0 "admin example usage report"27echo "--- cost_report (daily, by workspace)";           adm "/v1/organizations/cost_report?starting_at=$start&group_by[]=workspace_id" | mask | jq -c '.' | cut -c1-40028log_request anthropic GET /v1/organizations/cost_report "$ADM_STATUS" 0 "admin example cost report"29echo "--- usage_report/claude_code ($day)";             adm "/v1/organizations/usage_report/claude_code?starting_at=$day&limit=5" | mask | jq -c '.' | cut -c1-40030log_request anthropic GET /v1/organizations/usage_report/claude_code "$ADM_STATUS" 0 "admin example claude code analytics"31