How to Use Claude Code Analytics via API

Unlock insights with the Claude Code Analytics API! Track developer activity, productivity metrics, and costs for Claude Code usage. Learn to integrate with dashboards and optimize AI workflows with this REST API.

Ashley Goolam

Ashley Goolam

12 September 2025

How to Use Claude Code Analytics via API

Artificial Intelligence is transforming how teams code and having clear visibility into tool usage and productivity is a game-changer. Thats where the Claude Code Analytics API, a powerful tool from Anthropic unlocks deep insights into how an organization leverages Claude Code, their AI-powered coding assistant. This API isn’t just about numbers—it’s about empowering teams to track developer activity, optimize workflows, and manage costs with precision. Whether you’re a project lead ensuring your team maximizes AI tools or a CTO justifying investments, the Claude Code Analytics API delivers actionable data to make informed decisions. In this guide, we’ll explore what this API does, its core features, how to use it, and why it’s a must-have for organizations scaling AI-assisted coding. Let’s dive in and see how the Claude Code Analytics API can transform your team’s productivity!

💡
Want a great API Testing tool that generates beautiful API Documentation?

Want an integrated, All-in-One platform for your Developer Team to work together with maximum productivity?

Apidog delivers all your demands, and replaces Postman at a much more affordable price!
button

What is the Claude Code Analytics API

The Claude Code Analytics API is like a window into your organization’s use of Claude Code, Anthropic’s AI coding assistant. It provides programmatic access to detailed usage analytics and productivity metrics, giving you a clear picture of how developers are interacting with Claude Code. Whether it’s tracking lines of code generated, monitoring API usage, or analyzing costs, this API is your go-to for transparency. Available as a dedicated endpoint under the Anthropic platform (/v1/organizations/usage_report/claude_code), it’s designed for organizations using Claude Code to scale their development efforts. With the Claude Code Analytics API, you can answer critical questions like: Are developers fully utilizing Claude Code? Which tools are they using most? How much are we spending on AI models? This level of insight is invaluable for aligning AI adoption with business goals.

Claude Code Analytics API

Core Features and Capabilities of Claude's Analytics API

What makes the Claude Code Analytics API stand out? It’s packed with features that cater to both technical and business needs. Here’s the rundown:

These features make the Claude Code Analytics API a robust tool for understanding and optimizing Claude Code usage, whether you’re managing a small team or a large enterprise.

Technical Details and Usage

Ready to get your hands dirty with the Claude Code Analytics API? It’s a REST API, so it’s straightforward to use if you’re familiar with HTTP requests. The endpoint is /v1/organizations/usage_report/claude_code, and you’ll need an Admin API key (starting with sk-ant-admin...) to access it. You can generate this key in the Anthropic Console under Settings > API Keys, but only admins can do this—so make sure your organization is set up in Console > Settings > Organization.

Here’s a quick example to fetch analytics for a specific day using curl:

curl "https://api.anthropic.com/v1/organizations/usage_report/claude_code?starting_at=2025-09-08&limit=20" \
  --header "anthropic-version: 2023-06-01" \
  --header "x-api-key: $ADMIN_API_KEY" \
  --header "User-Agent: MyApp/1.0.0 (https://myapp.com)"

Let’s break it down:

The response is a JSON object with fields like user_id, sessions, lines_added, lines_removed, commits, tool_usage, and cost_usd, giving you a detailed snapshot of activity. For full schema details, check Anthropic’s API reference at docs.anthropic.com.

Testing API Endpoints with Apidog

Before integrating the Claude Code Analytics API into your workflows, it’s smart to test your API endpoints to ensure everything’s running smoothly. That’s where Apidog comes in—a fantastic tool for designing, testing, and debugging APIs. Apidog is especially helpful for developers working on projects that rely on APIs like Claude Code Analytics. Here’s how you can use it:

button
use apidog for testing api endpoints

Testing with Apidog ensures your Claude Code Analytics API integration is rock-solid, saving you from surprises when scaling to dashboards or reporting tools. It’s a must for any project involving API-driven analytics.

Community-Built Dashboards with Claude Code Analytics API

The Claude Code Analytics API has sparked creativity in the developer community, leading to custom dashboards for visualizing usage. A prime example is the Claude Code Templates project, an open-source dashboard that runs locally to monitor all your Claude Code sessions in real-time.

Get Started: Install and run it directly with the command npx claude-code-templates@latest --analytics. This spins up a local dashboard at localhost:3333—ensuring no data leaves your machine. The dashboard features token usage charts, project activity breakdowns, and export capabilities. It's a powerful tool for developers to gain immediate, private insights into their AI workflow patterns and costs.

Community-Built Dashboards with Claude Code Analytics API

These community projects show how versatile the Claude Code Analytics API is. You can deploy these dashboards on your servers or cloud platforms like Vercel or Render, giving your team real-time insights into Claude Code usage.

Integration and Developer Experience

The Claude Code Analytics API is designed for seamless integration. Its RESTful nature and consistent JSON responses make it easy to plug into dashboards, billing systems, or custom tools. Here’s how you can make it work for you:

For example, a Python script to fetch and process data might look like this:

import requests

def fetch_claude_analytics(api_key, date, limit=20, cursor=None):
    url = "https://api.anthropic.com/v1/organizations/usage_report/claude_code"
    headers = {
        "anthropic-version": "2023-06-01",
        "x-api-key": api_key,
        "User-Agent": "MyApp/1.0.0 (https://myapp.com)"
    }
    params = {"starting_at": date, "limit": limit}
    if cursor:
        params["cursor"] = cursor
    
    response = requests.get(url, headers=headers, params=params)
    response.raise_for_status()
    return response.json()

# Example usage
api_key = "your-admin-api-key"
data = fetch_claude_analytics(api_key, "2025-09-08")
for record in data["records"]:
    print(f"User: {record['user_id']}, Sessions: {record['sessions']}, Cost: ${record['cost_usd']:.2f}")

This script fetches data for a given date and prints key metrics. You can extend it to store results in a database or generate charts for your team.

Claude's Analytics API's Limitations and Considerations

While the Claude Code Analytics API is powerful, it has a few quirks to keep in mind:

These considerations don’t diminish the API’s value but help you plan its use effectively.

Conclusion

The Claude Code Analytics API is a must-have for organizations embracing AI-assisted coding with Claude Code. It offers unmatched visibility into developer activity, productivity, and costs, making it a cornerstone for data-driven decisions. Whether you’re building dashboards, optimizing budgets, or justifying AI investments, this API delivers the insights you need. Anthropic’s commitment to transparency shines through, and with potential future enhancements—like real-time data or deeper integrations—the Claude Code Analytics API is set to evolve further. So, grab your API key, fire up a curl command, and start unlocking the full potential of your team’s Claude Code usage today!

button
download apidog

Explore more

How to Use ChatGPT’s MCP Server Support with Connectors in Developer Mode

How to Use ChatGPT’s MCP Server Support with Connectors in Developer Mode

Unlock ChatGPT’s MCP support to connect with MCP servers using ChatGPT connectors. Learn how to add, create, and test custom MCP servers with OpenAI’s SDK and Apidog, plus which plans enable this powerful feature for smooth API integration.

12 September 2025

How to Use Claude's New Code Interpreter

How to Use Claude's New Code Interpreter

Claude’s new Code Interpreter (2025) lets you run Python/Node.js, create Excel/PDFs, and analyze data in a secure sandbox. Discover its features, use cases, and community dashboards!

12 September 2025

apiDoc vs Apidog: Which API Documentation Tool To Choose in 2025

apiDoc vs Apidog: Which API Documentation Tool To Choose in 2025

Confused by apiDoc vs. Apidog? This guide explains the difference between the code annotation tool and the all-in-one platform to streamline your API workflow.

12 September 2025

Practice API Design-first in Apidog

Discover an easier way to build and use APIs