anthropic
Run Claude inference, count tokens, and manage models, batches, files, skills, agents, deployments, environments, sessions, memory stores, dreams, user profiles and vaults on the Anthropic API using SQL.
For organization administration (users, invites, workspaces, API keys, usage/cost reports, rate limits, Claude Code analytics) use the anthropic_admin provider - it authenticates with a separate, org-scoped Admin key.
total services: 12 total resources: 39
See also: [SHOW] [DESCRIBE] [REGISTRY]
Installation
REGISTRY PULL anthropic;
Authentication
The anthropic provider authenticates with a workspace-scoped Claude API key (sk-ant-api...) sent in the x-api-key header. Set the following environment variable:
ANTHROPIC_API_KEY- a Claude API key, created in the Claude Console
The required anthropic-version header is sent automatically (default 2023-06-01); beta endpoints automatically send the per-endpoint anthropic-beta flag. Either can be overridden per query by supplying the header as a WHERE clause parameter.
Workspace-scoped queries
A key that can act on more than one workspace selects the workspace per query with the optional anthropic-workspace-id parameter (a wrkspc_... id, listed by the anthropic_admin provider's workspaces resource). It is sent as a header; the hyphenated name is double-quoted in SQL:
SELECT id, display_name, created_at
FROM anthropic.models.models
WHERE "anthropic-workspace-id" = 'wrkspc_01';
A key that belongs to one workspace can omit it.
Example Queries
Try the following queries using stackql shell, or run them from a script or CI pipeline with stackql exec.
Inference as a result set
Asking Claude a question is a SELECT. The reply comes back as a row, with the text in the content array and the token spend in usage:
SELECT
JSON_EXTRACT(content, '$[0].text') AS reply,
JSON_EXTRACT(usage, '$.input_tokens') AS input_tokens,
JSON_EXTRACT(usage, '$.output_tokens') AS output_tokens,
stop_reason
FROM anthropic.messages.messages
WHERE model = 'claude-sonnet-5'
AND max_tokens = 256
AND thinking = '{"type": "disabled"}'
AND messages = '[{"role": "user", "content": "Name the four Galilean moons of Jupiter, comma separated."}]';
Token counting is free of charge, so a prompt can be priced before it is sent:
SELECT input_tokens
FROM anthropic.messages.token_counts
WHERE model = 'claude-sonnet-5'
AND messages = '[{"role": "user", "content": "Name the four Galilean moons of Jupiter, comma separated."}]';
Which model can do what
The vw_model_capabilities view fans each model's capability flags out into columns, so picking a model for a workload is a WHERE clause:
SELECT id, display_name, thinking, image_input, pdf_input, batch, structured_outputs
FROM anthropic.models.vw_model_capabilities
ORDER BY created_at DESC;
Batch progress and triage
Message batches, newest first, with their per-request tallies:
SELECT
id,
processing_status,
JSON_EXTRACT(request_counts, '$.processing') AS processing,
JSON_EXTRACT(request_counts, '$.succeeded') AS succeeded,
JSON_EXTRACT(request_counts, '$.errored') AS errored,
created_at,
ended_at
FROM anthropic.messages.batches
ORDER BY created_at DESC;
Files and skills
Uploaded files, newest first (the list is cursor-paginated and walked automatically):
SELECT id, filename, mime_type, size_bytes, created_at
FROM anthropic.files.files
ORDER BY created_at DESC;
Skills available to the workspace, with their origin (anthropic for the published skills, custom for your own) and latest version:
SELECT id, display_name, JSON_EXTRACT(source, '$.type') AS source, latest_version_id, updated_at
FROM anthropic.skills.skills
ORDER BY updated_at DESC;
Uploading a file or creating a skill version is a multipart request, which SQL cannot express; those methods are documented as EXEC and the rest of each resource (list, get, delete) is plain SQL.
Agent inventory
What agents exist, on which models, and how much tooling they carry:
SELECT
id,
name,
model,
version,
JSON_ARRAY_LENGTH(tools) AS tool_count,
JSON_ARRAY_LENGTH(skills) AS skill_count,
updated_at
FROM anthropic.agents.agents
ORDER BY updated_at DESC;
Agent lifecycle
Agents are created, read and archived with the corresponding SQL verbs:
-- create
INSERT INTO anthropic.agents.agents (name, model)
SELECT 'release-notes-writer', 'claude-sonnet-5'
RETURNING id, name;
-- read
SELECT id, name, model, version, updated_at
FROM anthropic.agents.agents
WHERE agent_id = 'agent_01';
-- archive
EXEC anthropic.agents.agents.archive @agent_id = 'agent_01';
Dreams
Dreams are asynchronous memory-consolidation jobs over a memory store (a research preview: the endpoint returns 404 for keys that are not enrolled). Their status and inputs are rows:
SELECT id, status, JSON_ARRAY_LENGTH(inputs) AS input_count, created_at, ended_at
FROM anthropic.dreams.dreams
ORDER BY created_at DESC;