// Admin API read-only probes with the official TypeScript SDK (client.beta.organization.*). // STATUS: organization.retrieve() → LIVE_VERIFIED 2026-09-18 with the REGULAR key (200). // usage/cost/claude_code reports → ACCOUNT_RESTRICTED with a regular key (401 "The Admin API requires an Admin API key // or an organization-scoped API key."); executed for real only when ANTHROPIC_ADMIN_KEY is set in .env. // Run: node --env-file=.env --experimental-strip-types examples/anthropic/admin/org_me_and_usage_report.ts import Anthropic from "@anthropic-ai/sdk"; const client = new Anthropic(); // ANTHROPIC_API_KEY (or ANTHROPIC_AUTH_TOKEN for an org:admin OAuth token) const org = await client.beta.organization.retrieve(); console.log("organization:", org.id, org.name); const adminKey = process.env.ANTHROPIC_ADMIN_KEY; const start = new Date(Date.now() - 7 * 86_400_000).toISOString().slice(0, 10) + "T00:00:00Z"; const day = new Date(Date.now() - 86_400_000).toISOString().slice(0, 10); if (!adminKey) { console.log("ANTHROPIC_ADMIN_KEY not set — reports are ACCOUNT_RESTRICTED with a regular key (401). Skipping."); } else { // The Node SDK surface (sources/anthropic/openapi/node-sdk-api.md) exposes no usage/cost report methods yet → raw fetch. const get = async (path: string) => { const res = await fetch(`https://api.anthropic.com${path}`, { headers: { "x-api-key": adminKey, "anthropic-version": "2023-06-01" } }); return { status: res.status, body: (await res.json()) as any }; }; const usage = await get(`/v1/organizations/usage_report/messages?starting_at=${start}&bucket_width=1d&group_by[]=model&group_by[]=service_tier`); console.log("usage_report/messages", usage.status, JSON.stringify(usage.body).slice(0, 400)); const cost = await get(`/v1/organizations/cost_report?starting_at=${start}&group_by[]=workspace_id`); console.log("cost_report", cost.status, JSON.stringify(cost.body).slice(0, 400)); const cc = await get(`/v1/organizations/usage_report/claude_code?starting_at=${day}&limit=5`); console.log("usage_report/claude_code", cc.status, JSON.stringify(cc.body).slice(0, 400)); }