Skip to content

Anthropic

Read-only view of your Anthropic organization's members, API keys, token usage and cost

Connector software
Free and open source
Service credentials
Required
Use with an agent

Install the Orchard skill in your project to help your agent find connectors, configure them, and verify SQL results.

npx skills add Query-farm/vgi-skills --skill orchard

Copy this request into your coding agent to get started.

Use https://query.farm/products/orchard/connectors/anthropic/index.md to help me query Anthropic with DuckDB or Haybarn 2.0.1 and VGI protocol 3.4. Ask only for missing details about the result I need or whether I want local execution, self-hosting or Query Farm hosting. Check the connector's actual hosting availability, credentials and input requirements. Read one format of each needed reference and the exact object declarations before writing SQL. Use a released connector, and distinguish a saved example result from anything you actually execute. If you cannot run the query, tell me what remains to verify.

Track Claude spending by workspace

Uses your connected account. Set up the connector and credentials to run it with your data.

SELECT COALESCE(w.name, 'Default') AS workspace, sum(c.amount_usd) AS usd
FROM anthropic.main.cost_report(date_trunc('month', current_date)) c
LEFT JOIN anthropic.main.workspaces w ON w.id = c.workspace_id
GROUP BY ALL
ORDER BY usd DESC

Quick start

Choose where to run Anthropic, then follow the steps below.

The connector runs alongside DuckDB or Haybarn. No Query Farm account is needed.

1. Install the vgi extension

Run this in your SQL client. On DuckDB, keep FROM query_farm on LOAD in later sessions.

setup.sql
SET allow_extension_repositories = 'allowed';

CREATE EXTENSION REPOSITORY IF NOT EXISTS query_farm
    WITH PREFIX 'https://duckdb-extensions.query.farm';

INSTALL vgi FROM query_farm;
LOAD vgi FROM query_farm;

2. Attach the connector

Attach with uvx

Needs uv. uvx builds the worker from its release tag on first attach and reuses the cached environment after that.

ATTACH 'anthropic' AS anthropic (
  TYPE vgi,
  LOCATION 'uvx --from git+https://github.com/Query-farm/[email protected] vgi-anthropic'
);

3. Add service credentials

After attaching, create the secret for the service you want to query in the same SQL session. Replace the placeholders with your service settings.

anthropic_admin credentials

Anthropic Admin API credentials. Provide api_key (an Admin API key, sk-ant-admin01-..., or an organization-scoped personal or service-account key) or oauth_token (an OAuth access token with the org:admin scope). Required: every object in this catalog reads organization data.

Get these credentials β†’
secret.sql
CREATE SECRET anthropic_admin (
    TYPE anthropic_admin,
    api_key     '<ANTHROPIC_ADMIN_API_KEY>',  -- secret
    oauth_token '<OAUTH_TOKEN>'  -- secret
);
Credential fields and requirements β†’

4. Run a query

query.sql
SELECT COALESCE(w.name, 'Default') AS workspace, sum(c.amount_usd) AS usd
FROM anthropic.main.cost_report(date_trunc('month', current_date)) c
LEFT JOIN anthropic.main.workspaces w ON w.id = c.workspace_id
GROUP BY ALL
ORDER BY usd DESC
More example queries β†’
Technical details
Verified connector release
v0.2.1
Engine
2.0.1
VGI protocol
3.4.0
Verified on
December 1, 2026
Release notes on GitHub
Pin a version for production

When running the connector yourself, keep a specific release until you’re ready to upgrade. Replace the ATTACH statement above with this one and follow the same extension and credential setup.

Attach with uvx

Needs uv. uvx builds the worker from its release tag on first attach and reuses the cached environment after that.

ATTACH 'anthropic' AS anthropic (
  TYPE vgi,
  LOCATION 'uvx --from git+https://github.com/Query-farm/[email protected] vgi-anthropic'
);

Overview

Read-only Anthropic organization data: members, workspaces, API keys, rate limits, token usage, cost and Claude Code analytics

Catalog

Everything anthropic exposes once attached β€” read straight from the worker's released build.

anthropic 1 schema
main 8 tables Β· 14 functions

Anthropic Admin, Usage & Cost APIs β€” requires an anthropic_admin secret

Schema examples (10)
Examples (10)

Which organization is this?

SELECT id, name FROM anthropic.main.organization;

Members by role

SELECT role, count(*) AS members
FROM anthropic.main.users
GROUP BY role
ORDER BY members DESC;

Token volume by model over the last week

SELECT model, sum(output_tokens) AS output_tokens
FROM anthropic.main.messages_usage(current_date - INTERVAL 7 DAY)
GROUP BY model
ORDER BY output_tokens DESC;

Month-to-date spend by workspace, with names

SELECT COALESCE(w.name, 'Default') AS workspace, sum(c.amount_usd) AS usd
FROM anthropic.main.cost_report(date_trunc('month', current_date)) c
LEFT JOIN anthropic.main.workspaces w ON w.id = c.workspace_id
GROUP BY ALL
ORDER BY usd DESC;
6 more examples

Active keys nobody has used in 30 days

SELECT k.name, k.created_at
FROM anthropic.main.api_keys k
WHERE k.status = 'active' AND k.id NOT IN (SELECT api_key_id FROM anthropic.main.messages_usage(current_date - INTERVAL 30 DAY) WHERE api_key_id IS NOT NULL);

Last week's Claude Code usage per developer

SELECT email_address, sum(num_sessions) AS sessions,
  sum(estimated_cost_usd) AS usd
FROM anthropic.main.claude_code_usage(current_date - INTERVAL 7 DAY, ending_date => current_date)
WHERE actor_type = 'user_actor'
GROUP BY email_address
ORDER BY usd DESC;

Claude Code sessions, lines added and estimated cost over the last week, by organization role

SELECT u.role, count(DISTINCT u.email) AS people,
  sum(c.num_sessions) AS sessions, sum(c.lines_added) AS lines_added,
  sum(c.estimated_cost_usd) AS usd
FROM anthropic.main.claude_code_usage(current_date - INTERVAL 7 DAY, ending_date => current_date) c
JOIN anthropic.main.users u ON u.email = c.email_address
GROUP BY u.role
ORDER BY sessions DESC;

Members who have not used Claude Code in the last 30 days

SELECT u.email, u.role
FROM anthropic.main.users u
WHERE u.email NOT IN (SELECT email_address FROM anthropic.main.claude_code_usage(current_date - INTERVAL 30 DAY, ending_date => current_date) WHERE email_address IS NOT NULL)
ORDER BY u.email;

Today's peak output tokens per minute in each model group with usage, as a share of that group's output-tokens-per-minute limit

WITH per_minute AS (SELECT u.bucket_start, r.group_display_name, r.value AS otpm_limit, sum(u.output_tokens) AS otpm FROM anthropic.main.messages_usage(current_date, bucket_width => '1m') u JOIN anthropic.main.rate_limits r ON list_contains(r.models, u.model) AND r.limit_type = 'output_tokens_per_minute' GROUP BY ALL) SELECT group_display_name, otpm_limit, max(otpm) AS peak_otpm, round(100.0 * max(otpm) / otpm_limit, 2) AS peak_pct_of_limit
FROM per_minute
GROUP BY group_display_name, otpm_limit
ORDER BY peak_pct_of_limit DESC;

Month-to-date spend, tokens and blended dollars per million tokens, by model

WITH spend AS (SELECT model, sum(amount_usd) AS usd FROM anthropic.main.cost_report(date_trunc('month', current_date)) WHERE model IS NOT NULL GROUP BY model), tokens AS (SELECT model, sum(uncached_input_tokens + cache_read_input_tokens + cache_creation_5m_input_tokens + cache_creation_1h_input_tokens + output_tokens) AS tokens FROM anthropic.main.messages_usage(date_trunc('month', current_date)) GROUP BY model) SELECT s.model, s.usd, t.tokens, round(s.usd * 1000000 / nullif(t.tokens, 0), 2) AS usd_per_million_tokens
FROM spend s
JOIN tokens t USING (model)
ORDER BY s.usd DESC;
Tables
api_keys 1 example13 cols

Metadata of every API key in the organization (never the secret)

Columns
idnot null VARCHAR
API key ID (apikey_...). Not the secret, which the API never returns.
name VARCHAR
The key's name.
status VARCHAR
active, inactive, archived or expired.
created_at TIMESTAMP WITH TIME ZONE
When the key was created.
expires_at TIMESTAMP WITH TIME ZONE
When the key expires; NULL if it never does.
partial_key_hint VARCHAR
Redacted hint of the key value, e.g. sk-ant-api03-R2D...igAA.
workspace_id VARCHAR
Workspace the key belongs to β€” its real ID even for the default workspace. NULL for an organization-scoped key (scope_type = 'organization').
scope_type VARCHAR
workspace, or organization for a principal-bound key with no workspace.
created_by_type VARCHAR
user or service_account; NULL when the creator is not recorded.
created_by_id VARCHAR
ID of the user or service account that created the key.
principal_type VARCHAR
user_actor or service_account_actor; NULL when not principal-bound.
principal_user_id VARCHAR
User the key acts as, when principal_type = 'user_actor'.
principal_service_account_id VARCHAR
Service account the key acts as, when principal_type = 'service_account_actor'.
ConstraintsPRIMARY KEY (id)
Example

Active keys without an expiry

SELECT name, created_at
FROM anthropic.main.api_keys
WHERE status = 'active' AND expires_at IS NULL;
Link
invites 1 example8 cols

Invites to join the organization: pending, accepted and expired

Columns
idnot null VARCHAR
Invite ID (invite_...).
email VARCHAR
The address the invite was sent to.
role VARCHAR
Organization role the invitee will receive. Organization role. Console/API organizations use user, developer, billing, admin and claude_code_user; Claude Enterprise organizations use user, owner, primary_owner, membership_admin and managed.
status VARCHAR
pending, accepted, expired or deleted. An expired invite still lists until removed.
invited_at TIMESTAMP WITH TIME ZONE
When the invite was sent.
expires_at TIMESTAMP WITH TIME ZONE
When the invite stops being redeemable.
accepted_at TIMESTAMP WITH TIME ZONE
When the invite was accepted; NULL if it has not been.
rbac_group_ids VARCHAR[]
RBAC groups the user joins on acceptance (Claude Enterprise); empty when none.
ConstraintsPRIMARY KEY (id)
Example

Outstanding invites

SELECT email, role, expires_at
FROM anthropic.main.invites
WHERE status = 'pending';
Link
organization 1 example2 cols

The organization the Admin credential belongs to

Columns
idnot null VARCHAR
Organization ID (a UUID).
name VARCHAR
Organization name.
ConstraintsPRIMARY KEY (id)
Example

Which organization is this?

SELECT id, name FROM anthropic.main.organization;
Link
rate_limits 2 examples7 cols

The organization's configured rate limits, one row per group and limiter

Columns
idnot null VARCHAR
The organization's rate-limit entry ID.
group_id VARCHAR
Rate-limit group ID (rlg_...), the same in every organization.
group_type VARCHAR
model_group (a model family, listed in models), batch, files, skills, token_count or web_search.
group_display_name VARCHAR
Model group name, e.g. 'Claude Sonnet 4.x'. Display only.
models VARCHAR[]
Models and aliases the limit applies to; NULL for non-model groups.
limit_typenot null VARCHAR
The limiter, e.g. requests_per_minute, input_tokens_per_minute, output_tokens_per_minute.
value BIGINT
The configured limit, in the limiter's own unit: requests or tokens per minute.
ConstraintsPRIMARY KEY (id, limit_type)
Examples (2)

Limits per model group

SELECT group_display_name, limit_type, value
FROM anthropic.main.rate_limits
WHERE group_type = 'model_group'
ORDER BY 1, 2;

Today's peak output tokens per minute in each model group with usage, as a share of that group's output-tokens-per-minute limit

WITH per_minute AS (SELECT u.bucket_start, r.group_display_name, r.value AS otpm_limit, sum(u.output_tokens) AS otpm FROM anthropic.main.messages_usage(current_date, bucket_width => '1m') u JOIN anthropic.main.rate_limits r ON list_contains(r.models, u.model) AND r.limit_type = 'output_tokens_per_minute' GROUP BY ALL) SELECT group_display_name, otpm_limit, max(otpm) AS peak_otpm, round(100.0 * max(otpm) / otpm_limit, 2) AS peak_pct_of_limit
FROM per_minute
GROUP BY group_display_name, otpm_limit
ORDER BY peak_pct_of_limit DESC;
Link
users 2 examples5 cols

Every member of the organization, with their role

Columns
idnot null VARCHAR
User ID (user_...). The key every per-user lookup takes.
email VARCHAR
The member's email address.
name VARCHAR
The member's display name.
role VARCHAR
Organization role. Console/API organizations use user, developer, billing, admin and claude_code_user; Claude Enterprise organizations use user, owner, primary_owner, membership_admin and managed.
added_at TIMESTAMP WITH TIME ZONE
When the member joined the organization.
ConstraintsPRIMARY KEY (id)
Examples (2)

Members by role

SELECT role, count(*) AS members FROM anthropic.main.users GROUP BY role;

Members who have not used Claude Code in the last 30 days

SELECT u.email, u.role
FROM anthropic.main.users u
WHERE u.email NOT IN (SELECT email_address FROM anthropic.main.claude_code_usage(current_date - INTERVAL 30 DAY, ending_date => current_date) WHERE email_address IS NOT NULL)
ORDER BY u.email;
Link
workspace_members 1 example3 cols

Each member's role in each active workspace

Columns
workspace_idnot null VARCHAR
Workspace the membership is in.
user_idnot null VARCHAR
Member's user ID; joins to users.id.
workspace_role VARCHAR
workspace_user, workspace_developer, workspace_restricted_developer, workspace_admin or workspace_billing.
ConstraintsPRIMARY KEY (workspace_id, user_id) Β· FOREIGN KEY (workspace_id) REFERENCES workspaces(id) Β· FOREIGN KEY (user_id) REFERENCES users(id)
Example

Members per workspace

SELECT workspace_id, count(*) AS members
FROM anthropic.main.workspace_members
GROUP BY workspace_id;
Link
workspace_rate_limits 1 example10 cols

Each active workspace's rate limits, with whether each is overridden or inherited

Columns
workspace_idnot null VARCHAR
Workspace the limit applies to.
rate_limit_id VARCHAR
The organization rate-limit entry this refines; joins to rate_limits.id.
group_id VARCHAR
Rate-limit group ID (rlg_...).
group_type VARCHAR
model_group (a model family, listed in models), batch, files, skills, token_count or web_search.
group_display_name VARCHAR
Model group name. Display only.
models VARCHAR[]
Models and aliases the limit applies to; NULL for non-model groups.
limit_typenot null VARCHAR
The limiter, e.g. requests_per_minute.
value BIGINT
The limit in force for this workspace, in the limiter's unit (requests or tokens per minute).
org_limit BIGINT
The organization-level value for the same limiter (same unit as value), for comparison.
source VARCHAR
workspace when the workspace overrides the limit; organization when it inherits it.
ConstraintsPRIMARY KEY (workspace_id, rate_limit_id, limit_type) Β· FOREIGN KEY (workspace_id) REFERENCES workspaces(id)
Example

Workspace overrides

SELECT workspace_id, limit_type, value, org_limit
FROM anthropic.main.workspace_rate_limits
WHERE source = 'workspace';
Link
workspaces 1 example13 cols

Every workspace, archived ones included (the default workspace is not listed)

Columns
idnot null VARCHAR
Workspace ID (wrkspc_...).
name VARCHAR
Workspace name.
created_at TIMESTAMP WITH TIME ZONE
When the workspace was created.
archived_at TIMESTAMP WITH TIME ZONE
When the workspace was archived; NULL while it is active.
is_archived BOOLEAN
Whether the workspace is archived (archived_at IS NOT NULL).
display_color VARCHAR
Hex colour the Console shows the workspace in.
tags MAP(VARCHAR, VARCHAR)
User-defined key/value tags.
workspace_geo VARCHAR
Region where the workspace's data is stored (immutable after creation).
default_inference_geo VARCHAR
Inference geo applied when a request does not name one: global or us.
allowed_inference_geos VARCHAR[]
Inference geos requests may name. NULL when unrestricted β€” see inference_geo_unrestricted.
inference_geo_unrestricted BOOLEAN
True when every inference geo is allowed (the API's 'unrestricted').
external_key_id VARCHAR
Customer-managed encryption key (CMEK) attached to the workspace; NULL when none.
compartment_id VARCHAR
Encryption compartment ID, referenced by CMEK key policies.
ConstraintsPRIMARY KEY (id)
Example

Active workspaces

SELECT id, name, created_at
FROM anthropic.main.workspaces
WHERE NOT is_archived;
Link
Table functions
all_api_keys () 1 example

Metadata of every API key in the organization (the scan backing api_keys)

No arguments
Returns columns
id VARCHAR
API key ID (apikey_...). Not the secret, which the API never returns.
name VARCHAR
The key's name.
status VARCHAR
active, inactive, archived or expired.
created_at TIMESTAMP WITH TIME ZONE
When the key was created.
expires_at TIMESTAMP WITH TIME ZONE
When the key expires; NULL if it never does.
partial_key_hint VARCHAR
Redacted hint of the key value, e.g. sk-ant-api03-R2D...igAA.
workspace_id VARCHAR
Workspace the key belongs to β€” its real ID even for the default workspace. NULL for an organization-scoped key (scope_type = 'organization').
scope_type VARCHAR
workspace, or organization for a principal-bound key with no workspace.
created_by_type VARCHAR
user or service_account; NULL when the creator is not recorded.
created_by_id VARCHAR
ID of the user or service account that created the key.
principal_type VARCHAR
user_actor or service_account_actor; NULL when not principal-bound.
principal_user_id VARCHAR
User the key acts as, when principal_type = 'user_actor'.
principal_service_account_id VARCHAR
Service account the key acts as, when principal_type = 'service_account_actor'.
Example

Active keys that never expire

SELECT name, workspace_id, created_at
FROM anthropic.main.all_api_keys()
WHERE status = 'active' AND expires_at IS NULL
ORDER BY created_at;
Link
all_invites () 1 example

Every invite the organization has sent (the scan backing invites)

No arguments
Returns columns
id VARCHAR
Invite ID (invite_...).
email VARCHAR
The address the invite was sent to.
role VARCHAR
Organization role the invitee will receive. Organization role. Console/API organizations use user, developer, billing, admin and claude_code_user; Claude Enterprise organizations use user, owner, primary_owner, membership_admin and managed.
status VARCHAR
pending, accepted, expired or deleted. An expired invite still lists until removed.
invited_at TIMESTAMP WITH TIME ZONE
When the invite was sent.
expires_at TIMESTAMP WITH TIME ZONE
When the invite stops being redeemable.
accepted_at TIMESTAMP WITH TIME ZONE
When the invite was accepted; NULL if it has not been.
rbac_group_ids VARCHAR[]
RBAC groups the user joins on acceptance (Claude Enterprise); empty when none.
Example

Invites still waiting to be accepted

SELECT email, role, expires_at
FROM anthropic.main.all_invites()
WHERE status = 'pending'
ORDER BY expires_at;
Link
all_organization () 1 example

The organization the Admin credential belongs to (the scan backing organization)

No arguments
Returns columns
id VARCHAR
Organization ID (a UUID).
name VARCHAR
Organization name.
Example

Which organization is this credential for?

SELECT id, name FROM anthropic.main.all_organization();
Link
all_rate_limits () 1 example

The organization's Messages API rate limits (the scan backing rate_limits)

No arguments
Returns columns
id VARCHAR
The organization's rate-limit entry ID.
group_id VARCHAR
Rate-limit group ID (rlg_...), the same in every organization.
group_type VARCHAR
model_group (a model family, listed in models), batch, files, skills, token_count or web_search.
group_display_name VARCHAR
Model group name, e.g. 'Claude Sonnet 4.x'. Display only.
models VARCHAR[]
Models and aliases the limit applies to; NULL for non-model groups.
limit_type VARCHAR
The limiter, e.g. requests_per_minute, input_tokens_per_minute, output_tokens_per_minute.
value BIGINT
The configured limit, in the limiter's own unit: requests or tokens per minute.
Example

Per-minute limits for every model group

SELECT group_display_name, limit_type, value
FROM anthropic.main.all_rate_limits()
WHERE group_type = 'model_group'
ORDER BY group_display_name, limit_type;
Link
all_users () 1 example

Every member of the organization (the scan backing users)

No arguments
Returns columns
id VARCHAR
User ID (user_...). The key every per-user lookup takes.
email VARCHAR
The member's email address.
name VARCHAR
The member's display name.
role VARCHAR
Organization role. Console/API organizations use user, developer, billing, admin and claude_code_user; Claude Enterprise organizations use user, owner, primary_owner, membership_admin and managed.
added_at TIMESTAMP WITH TIME ZONE
When the member joined the organization.
Example

Admins of the organization

SELECT email, name FROM anthropic.main.all_users() WHERE role = 'admin';
Link
all_workspace_members () 1 example

Every user's role in every active workspace (the scan backing workspace_members)

No arguments
Returns columns
workspace_id VARCHAR
Workspace the membership is in.
user_id VARCHAR
Member's user ID; joins to users.id.
workspace_role VARCHAR
workspace_user, workspace_developer, workspace_restricted_developer, workspace_admin or workspace_billing.
Example

Workspace admins with their emails

SELECT w.name, u.email
FROM anthropic.main.all_workspace_members() m
JOIN anthropic.main.users u ON u.id = m.user_id
JOIN anthropic.main.workspaces w ON w.id = m.workspace_id
WHERE m.workspace_role = 'workspace_admin'
ORDER BY w.name, u.email;
Link
all_workspace_rate_limits () 1 example

Each active workspace's rate limits, inherited and overridden (backs workspace_rate_limits)

No arguments
Returns columns
workspace_id VARCHAR
Workspace the limit applies to.
rate_limit_id VARCHAR
The organization rate-limit entry this refines; joins to rate_limits.id.
group_id VARCHAR
Rate-limit group ID (rlg_...).
group_type VARCHAR
model_group (a model family, listed in models), batch, files, skills, token_count or web_search.
group_display_name VARCHAR
Model group name. Display only.
models VARCHAR[]
Models and aliases the limit applies to; NULL for non-model groups.
limit_type VARCHAR
The limiter, e.g. requests_per_minute.
value BIGINT
The limit in force for this workspace, in the limiter's unit (requests or tokens per minute).
org_limit BIGINT
The organization-level value for the same limiter (same unit as value), for comparison.
source VARCHAR
workspace when the workspace overrides the limit; organization when it inherits it.
Example

Workspaces that override an organization limit

SELECT workspace_id, group_display_name, limit_type, value, org_limit
FROM anthropic.main.all_workspace_rate_limits()
WHERE source = 'workspace';
Link
all_workspaces () 1 example

Every workspace in the organization, archived included (the scan backing workspaces)

No arguments
Returns columns
id VARCHAR
Workspace ID (wrkspc_...).
name VARCHAR
Workspace name.
created_at TIMESTAMP WITH TIME ZONE
When the workspace was created.
archived_at TIMESTAMP WITH TIME ZONE
When the workspace was archived; NULL while it is active.
is_archived BOOLEAN
Whether the workspace is archived (archived_at IS NOT NULL).
display_color VARCHAR
Hex colour the Console shows the workspace in.
tags MAP(VARCHAR, VARCHAR)
User-defined key/value tags.
workspace_geo VARCHAR
Region where the workspace's data is stored (immutable after creation).
default_inference_geo VARCHAR
Inference geo applied when a request does not name one: global or us.
allowed_inference_geos VARCHAR[]
Inference geos requests may name. NULL when unrestricted β€” see inference_geo_unrestricted.
inference_geo_unrestricted BOOLEAN
True when every inference geo is allowed (the API's 'unrestricted').
external_key_id VARCHAR
Customer-managed encryption key (CMEK) attached to the workspace; NULL when none.
compartment_id VARCHAR
Encryption compartment ID, referenced by CMEK key policies.
Example

Active workspaces, newest first

SELECT id, name, created_at
FROM anthropic.main.all_workspaces()
WHERE NOT is_archived
ORDER BY created_at DESC;
Link
api_key_by_id (api_key_id VARCHAR) 1 example

One API key's metadata by ID (never the secret; no row if it does not exist)

Arguments
api_key_id VARCHAR
API key ID input column (apikey_...)
Returns columns
id VARCHAR
API key ID (apikey_...). Not the secret, which the API never returns.
name VARCHAR
The key's name.
status VARCHAR
active, inactive, archived or expired.
created_at TIMESTAMP WITH TIME ZONE
When the key was created.
expires_at TIMESTAMP WITH TIME ZONE
When the key expires; NULL if it never does.
partial_key_hint VARCHAR
Redacted hint of the key value, e.g. sk-ant-api03-R2D...igAA.
workspace_id VARCHAR
Workspace the key belongs to β€” its real ID even for the default workspace. NULL for an organization-scoped key (scope_type = 'organization').
scope_type VARCHAR
workspace, or organization for a principal-bound key with no workspace.
created_by_type VARCHAR
user or service_account; NULL when the creator is not recorded.
created_by_id VARCHAR
ID of the user or service account that created the key.
principal_type VARCHAR
user_actor or service_account_actor; NULL when not principal-bound.
principal_user_id VARCHAR
User the key acts as, when principal_type = 'user_actor'.
principal_service_account_id VARCHAR
Service account the key acts as, when principal_type = 'service_account_actor'.
Example

Look up one key

SELECT name, status
FROM anthropic.main.api_key_by_id((SELECT id FROM anthropic.main.api_keys LIMIT 1));
Link
claude_code_usage (starting_date ANY, cache_ttl := BIGINT, ending_date := ANY) 3 examples

Daily Claude Code sessions, lines changed, commits, PRs, tokens and cost per user

Positional arguments
starting_date ANY
First UTC day to report
Named arguments
cache_ttl := BIGINT
Seconds to cache the result (0 = off) Β· default 0
ending_date := ANY
Last UTC day to report, inclusive; omit for just starting_date Β· default null
Returns columns
date DATE
UTC day the metrics cover.
actor_type VARCHAR
user_actor (a person) or api_actor (an API key).
email_address VARCHAR
The user's email, for user_actor rows.
api_key_name VARCHAR
The API key's name, for api_actor rows.
organization_id VARCHAR
Organization that owns the usage.
customer_type VARCHAR
api (API customers) or subscription (Pro/Team/Enterprise).
subscription_type VARCHAR
team or enterprise for subscription customers; NULL for api.
terminal_type VARCHAR
Terminal or environment Claude Code ran in, e.g. iTerm.app, vscode.
is_remote BOOLEAN
Whether the usage came from remote sessions (e.g. Claude Code on the web). Remote and local usage are separate rows.
num_sessions BIGINT
Distinct Claude Code sessions.
lines_added BIGINT
Lines of code added by Claude Code.
lines_removed BIGINT
Lines of code removed by Claude Code.
commits BIGINT
Git commits created through Claude Code.
pull_requests BIGINT
Pull requests created through Claude Code.
input_tokens BIGINT
Input tokens, summed across models.
output_tokens BIGINT
Output tokens, summed across models.
cache_read_tokens BIGINT
Cache-read tokens, summed across models.
cache_creation_tokens BIGINT
Cache-creation tokens, summed across models.
estimated_cost_cents DECIMAL(38,12)
Estimated cost in cents, summed across models.
estimated_cost_usd DECIMAL(38,14)
Estimated cost in dollars, summed across models.
model_breakdown STRUCT of 8 fields[]
Per-model tokens and estimated cost; UNNEST it for one row per model.
STRUCT[] 8 fields
  • modelVARCHAR
  • input_tokensBIGINT
  • output_tokensBIGINT
  • cache_read_tokensBIGINT
  • cache_creation_tokensBIGINT
  • estimated_cost_centsDECIMAL(38,12)
  • estimated_cost_usdDECIMAL(38,14)
  • currencyVARCHAR
tool_actions MAP(VARCHAR, STRUCT("accepted" BIGINT, "rejected" BIGINT))
Accepted/rejected tool proposals by tool, e.g. tool_actions['edit_tool'].accepted.
Examples (3)

Last week's Claude Code leaderboard

SELECT email_address, sum(num_sessions) AS sessions,
  sum(lines_added) AS lines_added, sum(estimated_cost_usd) AS usd
FROM anthropic.main.claude_code_usage(current_date - INTERVAL 7 DAY, ending_date => current_date)
WHERE actor_type = 'user_actor'
GROUP BY email_address
ORDER BY usd DESC;

Edit acceptance rate by day

SELECT date,
  sum(tool_actions['edit_tool'].accepted) / nullif(sum(tool_actions['edit_tool'].accepted + tool_actions['edit_tool'].rejected), 0) AS acceptance
FROM anthropic.main.claude_code_usage(current_date - INTERVAL 14 DAY, ending_date => current_date)
GROUP BY date
ORDER BY date;

Claude Code sessions, lines added and estimated cost over the last week, by organization role

SELECT u.role, count(DISTINCT u.email) AS people,
  sum(c.num_sessions) AS sessions, sum(c.lines_added) AS lines_added,
  sum(c.estimated_cost_usd) AS usd
FROM anthropic.main.claude_code_usage(current_date - INTERVAL 7 DAY, ending_date => current_date) c
JOIN anthropic.main.users u ON u.email = c.email_address
GROUP BY u.role
ORDER BY sessions DESC;
Link
cost_report (starting_at ANY, cache_ttl := BIGINT, ending_at := ANY, group_by := VARCHAR[]) 3 examples

Daily spend in USD, by workspace and line item (model, token type, tool)

Positional arguments
starting_at ANY
Start of the report (inclusive), snapped down to the UTC day; strings read as UTC
Named arguments
cache_ttl := BIGINT
Seconds to cache the result (0 = off) Β· default 0
ending_at := ANY
End of the report (exclusive); defaults to now Β· default null
group_by := VARCHAR[]
Dimensions to break cost down by; omit to group by the columns the query uses Β· default []
Returns columns
bucket_start TIMESTAMP WITH TIME ZONE
Start of the time bucket (inclusive), UTC.
bucket_end TIMESTAMP WITH TIME ZONE
End of the time bucket (exclusive), UTC.
workspace_id VARCHAR
Workspace the cost accrued in. NULL for the default workspace, and when not grouped by it.
description VARCHAR
Line-item description, e.g. 'Claude Opus 5 Usage - Input Tokens'. This and the columns after it are NULL unless the report is grouped by description.
cost_type VARCHAR
tokens, web_search, code_execution or session_usage.
model VARCHAR
Model the cost is for; NULL for non-token costs.
service_tier VARCHAR
standard or batch; NULL for non-token costs.
token_type VARCHAR
uncached_input_tokens, output_tokens, cache_read_input_tokens, cache_creation.ephemeral_5m_input_tokens or cache_creation.ephemeral_1h_input_tokens.
context_window VARCHAR
0-200k or 200k-1M; NULL for non-token costs.
inference_geo VARCHAR
global, us or not_available.
currency VARCHAR
Currency of the amount; currently always USD.
amount_cents DECIMAL(38,12)
Cost in cents, exactly as the API reports it (a decimal, not a float).
amount_usd DECIMAL(38,14)
The same cost in dollars: amount_cents / 100, exact.
Examples (3)

Month-to-date spend by model

SELECT model, sum(amount_usd) AS usd
FROM anthropic.main.cost_report(date_trunc('month', current_date))
GROUP BY model
ORDER BY usd DESC;

Daily spend per workspace, with names

SELECT c.bucket_start::DATE AS day,
  COALESCE(w.name, 'Default') AS workspace, sum(c.amount_usd) AS usd
FROM anthropic.main.cost_report(current_date - INTERVAL 30 DAY) c
LEFT JOIN anthropic.main.workspaces w ON w.id = c.workspace_id
GROUP BY ALL
ORDER BY day, workspace;

Month-to-date spend, tokens and blended dollars per million tokens, by model

WITH spend AS (SELECT model, sum(amount_usd) AS usd FROM anthropic.main.cost_report(date_trunc('month', current_date)) WHERE model IS NOT NULL GROUP BY model), tokens AS (SELECT model, sum(uncached_input_tokens + cache_read_input_tokens + cache_creation_5m_input_tokens + cache_creation_1h_input_tokens + output_tokens) AS tokens FROM anthropic.main.messages_usage(date_trunc('month', current_date)) GROUP BY model) SELECT s.model, s.usd, t.tokens, round(s.usd * 1000000 / nullif(t.tokens, 0), 2) AS usd_per_million_tokens
FROM spend s
JOIN tokens t USING (model)
ORDER BY s.usd DESC;
Link
messages_usage (starting_at ANY, bucket_width := VARCHAR, cache_ttl := BIGINT, ending_at := ANY, group_by := VARCHAR[]) 4 examples

Messages API token usage over time, by model, workspace, API key and more

Positional arguments
starting_at ANY
Start of the report (inclusive), snapped down to the bucket boundary; strings read as UTC
Named arguments
bucket_width := VARCHAR
Bucket size: 1d, 1h or 1m Β· default "1d"
cache_ttl := BIGINT
Seconds to cache the result (0 = off) Β· default 0
ending_at := ANY
End of the report (exclusive); defaults to now Β· default null
group_by := VARCHAR[]
Dimensions to break usage down by; omit to group by the dimension columns the query uses Β· default []
Returns columns
bucket_start TIMESTAMP WITH TIME ZONE
Start of the time bucket (inclusive), UTC.
bucket_end TIMESTAMP WITH TIME ZONE
End of the time bucket (exclusive), UTC.
workspace_id VARCHAR
Workspace the usage ran in. NULL for the default workspace, and when not grouped by it.
api_key_id VARCHAR
API key used; NULL for Console usage and when not grouped by it.
account_id VARCHAR
User account (OAuth) that made the requests; NULL when not grouped by it.
service_account_id VARCHAR
Service account that made the requests; NULL when not grouped by it.
model VARCHAR
Model used; NULL when not grouped by it.
service_tier VARCHAR
standard, batch, priority, priority_on_demand, flex or flex_discount.
context_window VARCHAR
0-200k or 200k-1M.
inference_geo VARCHAR
global, us, or not_available for models without geo routing.
speed VARCHAR
standard or fast (fast mode). Only populated with group_by => ['speed'].
uncached_input_tokens BIGINT
Input tokens processed without a cache hit.
cache_read_input_tokens BIGINT
Input tokens read from the prompt cache.
cache_creation_5m_input_tokens BIGINT
Input tokens written to a 5-minute cache entry.
cache_creation_1h_input_tokens BIGINT
Input tokens written to a 1-hour cache entry.
output_tokens BIGINT
Output tokens generated.
web_search_requests BIGINT
Server-side web search tool requests.
Examples (4)

Token volume by model over the last week

SELECT model,
  sum(uncached_input_tokens + cache_read_input_tokens) AS input_tokens,
  sum(output_tokens) AS output_tokens
FROM anthropic.main.messages_usage(current_date - INTERVAL 7 DAY)
GROUP BY model
ORDER BY output_tokens DESC;

Hourly output tokens for one model today

SELECT bucket_start, sum(output_tokens) AS output_tokens
FROM anthropic.main.messages_usage(current_date, bucket_width => '1h')
WHERE model = 'claude-opus-5-5'
GROUP BY bucket_start
ORDER BY bucket_start;

Usage by API key name

SELECT k.name, sum(u.output_tokens) AS output_tokens
FROM anthropic.main.messages_usage(current_date - INTERVAL 30 DAY) u
LEFT JOIN anthropic.main.api_keys k ON k.id = u.api_key_id
GROUP BY k.name
ORDER BY output_tokens DESC;
1 more example

Today's peak output tokens per minute in each model group with usage, as a share of that group's output-tokens-per-minute limit

WITH per_minute AS (SELECT u.bucket_start, r.group_display_name, r.value AS otpm_limit, sum(u.output_tokens) AS otpm FROM anthropic.main.messages_usage(current_date, bucket_width => '1m') u JOIN anthropic.main.rate_limits r ON list_contains(r.models, u.model) AND r.limit_type = 'output_tokens_per_minute' GROUP BY ALL) SELECT group_display_name, otpm_limit, max(otpm) AS peak_otpm, round(100.0 * max(otpm) / otpm_limit, 2) AS peak_pct_of_limit
FROM per_minute
GROUP BY group_display_name, otpm_limit
ORDER BY peak_pct_of_limit DESC;
Link
user_by_id (user_id VARCHAR) 1 example

One organization member by user ID (no row if the user is gone)

Arguments
user_id VARCHAR
User ID input column (user_...)
Returns columns
id VARCHAR
User ID (user_...). The key every per-user lookup takes.
email VARCHAR
The member's email address.
name VARCHAR
The member's display name.
role VARCHAR
Organization role. Console/API organizations use user, developer, billing, admin and claude_code_user; Claude Enterprise organizations use user, owner, primary_owner, membership_admin and managed.
added_at TIMESTAMP WITH TIME ZONE
When the member joined the organization.
Example

Who created each active key

SELECT k.name, u.email
FROM anthropic.main.api_keys k
LEFT JOIN LATERAL anthropic.main.user_by_id(k.created_by_id) u ON true
WHERE k.status = 'active' AND k.created_by_type = 'user';
Link
workspace_by_id (workspace_id VARCHAR) 1 example

One workspace by ID (no row if it does not exist)

Arguments
workspace_id VARCHAR
Workspace ID input column (wrkspc_...)
Returns columns
id VARCHAR
Workspace ID (wrkspc_...).
name VARCHAR
Workspace name.
created_at TIMESTAMP WITH TIME ZONE
When the workspace was created.
archived_at TIMESTAMP WITH TIME ZONE
When the workspace was archived; NULL while it is active.
is_archived BOOLEAN
Whether the workspace is archived (archived_at IS NOT NULL).
display_color VARCHAR
Hex colour the Console shows the workspace in.
tags MAP(VARCHAR, VARCHAR)
User-defined key/value tags.
workspace_geo VARCHAR
Region where the workspace's data is stored (immutable after creation).
default_inference_geo VARCHAR
Inference geo applied when a request does not name one: global or us.
allowed_inference_geos VARCHAR[]
Inference geos requests may name. NULL when unrestricted β€” see inference_geo_unrestricted.
inference_geo_unrestricted BOOLEAN
True when every inference geo is allowed (the API's 'unrestricted').
external_key_id VARCHAR
Customer-managed encryption key (CMEK) attached to the workspace; NULL when none.
compartment_id VARCHAR
Encryption compartment ID, referenced by CMEK key policies.
Example

Look up one workspace

SELECT name, created_at
FROM anthropic.main.workspace_by_id((SELECT id FROM anthropic.main.workspaces LIMIT 1));
Link

Credentials

The secret type anthropic declares, as reported by the worker itself.

anthropic_admin

How to get these credentials

Anthropic Admin API credentials. Provide api_key (an Admin API key, sk-ant-admin01-..., or an organization-scoped personal or service-account key) or oauth_token (an OAuth access token with the org:admin scope). Required: every object in this catalog reads organization data.

secret.sql
CREATE SECRET anthropic_admin (
    TYPE anthropic_admin,
    api_key     '<ANTHROPIC_ADMIN_API_KEY>',  -- secret
    oauth_token '<OAUTH_TOKEN>'  -- secret
);
Key Type Required Description
api_key secret VARCHAR β€” An Admin API key (sk-ant-admin01-...) from Console > Settings > Admin keys, or an organization-scoped personal or service-account key. Set this or oauth_token.
oauth_token secret VARCHAR β€” An OAuth access token carrying the org:admin scope. Used only when api_key is not set.

The worker doesn't mark which keys are required.

Needed by all_organizationall_usersall_invitesall_workspacesall_workspace_membersall_api_keysall_rate_limitsall_workspace_rate_limitsmessages_usagecost_reportclaude_code_usageuser_by_id and 2 more functions

Create the secret in the same session, after attaching anthropic β€” the worker registers its secret types at ATTACH. Keys marked secret are masked in duckdb_secrets(); angle-bracket values are placeholders. Read credentials from your environment or secret store in your application and pass them through your SQL client’s parameter bindings. Keep real values out of saved SQL and history. Native DuckDB and Haybarn do not provide a SQL getenv() function.

Try these queries

credential_resolves_to_one_organization β€” The Admin credential belongs to exactly one organization.

SELECT count(*) = 1 FROM anthropic.main.organization;

Uses organization

someone_administers_the_organization β€” Whoever issued the Admin key is an admin, so the role exists.

SELECT count(*) > 0
FROM anthropic.main.users
WHERE role IN ('admin', 'owner', 'primary_owner');

Uses users

cost_is_exact_decimal β€” Money comes back as DECIMAL, never a float.

SELECT column_type
FROM (DESCRIBE SELECT amount_usd FROM anthropic.main.cost_report(current_date - INTERVAL 1 DAY));

Uses cost_report

usage_buckets_are_days_by_default β€” Default buckets are one day wide.

SELECT bool_and(bucket_end - bucket_start = INTERVAL 1 DAY) IS NOT FALSE
FROM anthropic.main.messages_usage(current_date - INTERVAL 3 DAY);

Uses messages_usage

Active keys nobody has used in 30 days

SELECT k.name, k.created_at
FROM anthropic.main.api_keys k
WHERE k.status = 'active' AND k.id NOT IN (SELECT api_key_id FROM anthropic.main.messages_usage(current_date - INTERVAL 30 DAY) WHERE api_key_id IS NOT NULL)

Uses api_keysmessages_usage

Last week's Claude Code usage per developer

SELECT email_address, sum(num_sessions) AS sessions,
  sum(estimated_cost_usd) AS usd
FROM anthropic.main.claude_code_usage(current_date - INTERVAL 7 DAY, ending_date => current_date)
WHERE actor_type = 'user_actor'
GROUP BY email_address
ORDER BY usd DESC

Uses claude_code_usage

1 more example

users_table_and_scan_agree β€” The `users` table and the `all_users` function behind it are the same rows.

SELECT (SELECT count(*) FROM anthropic.main.users) = (SELECT count(*) FROM anthropic.main.all_users());

Uses usersall_users

32 more examples in the Catalog, each listed under the table or function it uses.

Questions it can answer

Plain-English questions from the worker's agent test tasks. An AI agent with this catalog attached should answer each one with SQL.

  • Which Anthropic organization does this connection read from?
  • Who are the admins of our Anthropic organization?
  • Which invitations to join our organization are still outstanding, and when do they expire?
  • List our active workspaces and when each was created.
  • Who administers each workspace? Give workspace names and emails.
  • List our active API keys that have no expiry date.

Anthropic is an independent open-source connector from Query.Farm. It is not affiliated with, endorsed by or sponsored by the services, projects or organisations it works with. Product names, logos and trademarks belong to their respective owners.