[
    {
        "role": "user",
        "content": "ok%2C%20i%20went%20to%20claude.ai%2Fsettings%2Fusage%20to%20get%20my%20current%20usage.%20is%20there%20a%20command-line%20way%20of%20doing%20this%3F"
    },
    {
        "role": "assistant",
        "content": "Yes \u2014 Anthropic (the maker of Claude) provides a *Usage & Cost Admin API* which can be used from the command line to get your Claude usage (for organizations) programmatically. ([docs.claude.com](https://docs.claude.com/en/api/data-usage-cost-api?utm_source=openai))\n\nHere are the details, requirements, and example commands.\n\n---\n\n## \u2705 What you need\n\n- Your account must be part of an **Organization** in Claude (see *Console \u2192 Settings \u2192 Organization*) because individual accounts can\u2019t use the Admin API. ([docs.claude.com](https://docs.claude.com/en/api/data-usage-cost-api?utm_source=openai))  \n- You need an **Admin API key** (often starts with `sk-ant-admin\u2026`) with permissions to read usage/cost data. ([platform.claude.com](https://platform.claude.com/cookbook/observability-usage-cost-api?utm_source=openai))  \n- The HTTP header `anthropic-version` is required. It\u2019s usually set to `2023-06-01`. ([platform.claude.com](https://platform.claude.com/docs/claude/reference/getting-started-with-the-api?utm_source=openai))  \n\n---\n\n## \ud83d\udcbb How to request usage data via command-line (curl example)\n\nBelow are typical `curl` commands to fetch usage/cost:\n\n### Get daily usage by model\n\n```bash\ncurl \"https://api.anthropic.com/v1/organizations/usage_report/messages?\\\nstarting_at=2025-01-01T00:00:00Z&\\\nending_at=2025-01-08T00:00:00Z&\\\ngroup_by[]=model&\\\nbucket_width=1d\" \\\n  -H \"x-api-key: $ADMIN_API_KEY\" \\\n  -H \"anthropic-version: 2023-06-01\"\n```\n\nThis returns token usage grouped by model, with one \u201cbucket\u201d per day. ([docs.claude.com](https://docs.claude.com/en/api/data-usage-cost-api?utm_source=openai))\n\n### Get cost report\n\n```bash\ncurl \"https://api.anthropic.com/v1/organizations/cost_report?\\\nstarting_at=2025-01-01T00:00:00Z&\\\nending_at=2025-01-31T00:00:00Z&\\\ngroup_by[]=workspace_id&\\\ngroup_by[]=description\" \\\n  -H \"x-api-key: $ADMIN_API_KEY\" \\\n  -H \"anthropic-version: 2023-06-01\"\n```\n\nThis gives you costs in USD, broken down by workspace or description. ([docs.claude.com](https://docs.claude.com/en/api/data-usage-cost-api?utm_source=openai))\n\n---\n\n## \u2699\ufe0f Using the `ant` CLI\n\nAnthropic provides a CLI tool called `ant` which can talk to these endpoints (as well as many others) in a more convenient way than raw `curl`. ([platform.claude.com](https://platform.claude.com/docs/en/api/sdks/cli?utm_source=openai))\n\nYou could do something like:\n\n```bash\nant organizations usage_report messages \\\n  --starting-at 2025-01-01T00:00:00Z \\\n  --ending-at   2025-01-08T00:00:00Z \\\n  --group-by model \\\n  --bucket-width 1d \\\n  --format json\n```\n\n(Of course set your API key via environment variable or config file as supported by `ant`. ([platform.claude.com](https://platform.claude.com/docs/en/api/sdks/cli?utm_source=openai)))\n\n---\n\n## \ud83d\udea7 Caveats & Limitations\n\n- If you\u2019re *not* part of an organization, admin APIs won\u2019t work for you. Individual-account usage and plan-level usage (e.g. for Claude Code subscription plan) are more limited. ([docs.claude.com](https://docs.claude.com/en/api/data-usage-cost-api?utm_source=openai))  \n- Data is usually fresh within **5 minutes** for usage endpoints. Cost endpoints might take longer. ([docs.claude.com](https://docs.claude.com/en/api/data-usage-cost-api?utm_source=openai))  \n- Some endpoints are labeled **beta**; APIs might change or have limitations in what can be filtered/grouped. ([docs.claude.com](https://docs.claude.com/en/api/data-usage-cost-api?utm_source=openai))  \n\n---\n\nIf you tell me whether you\u2019re using Claude as an individual or via an organization, and which usage you want (API usage, cost, Claude Code plan usage, etc.), I can give you the exact command you\u2019d need."
    }
]