Last updated: February 17, 2026
Supported agents
Claude Code
Anthropic’s CLI coding agent. Works in any terminal or IDE with MCP support.
Gemini CLI
Google’s command-line AI agent with built-in MCP support.
Codex
OpenAI’s coding agent for the terminal, with MCP integration.
Prerequisites
- A Detrics account with at least one connected platform
- One of the supported coding agents installed:
- Claude Code by Anthropic
- Gemini CLI by Google
- Codex by OpenAI
Setup
Generate an API Key
Go to the Detrics web app and generate an API key. Give it a descriptive name (e.g., “My laptop” or “Work desktop”).The key will only be shown once — copy it before closing the dialog.
Install the MCP Server
Run the command for your coding agent in your terminal. Replace This registers the Detrics MCP server with your agent. No separate installation step is needed —
your-api-key with the key you just generated.- Claude Code
- Gemini CLI
- Codex
npx -y detrics handles everything automatically.Example prompts
Once connected, try these prompts:- “What was my total ad spend across all platforms last month?”
- “Compare my Google Ads and Meta Ads ROAS for the last 30 days”
- “Show me my top 5 campaigns by conversions this week”
- “What’s my Shopify revenue trend over the last 90 days?”
- “What metrics are available for TikTok Ads?”
Using AI Contexts
AI Contexts let you pre-select which platforms and accounts to query. Instead of specifying account IDs every time, you create a Context once and reference it by name.Updating your API key
If you need to replace your API key (e.g., after revoking an old one), remove the existing server and re-add it with your new key.- Claude Code
- Gemini CLI
- Codex
Troubleshooting
"detrics already exists" error
"detrics already exists" error
The server is already registered. Remove it first, then re-add it.
- Claude Code
- Gemini CLI
- Codex
"DETRICS_API_KEY is required" error
"DETRICS_API_KEY is required" error
The API key wasn’t passed correctly. Remove the server and re-add it, making sure the
-e DETRICS_API_KEY=... flag is included with your full key."Unauthorized" or invalid key error
"Unauthorized" or invalid key error
"No connections found" response
"No connections found" response
Your agent can reach Detrics, but there are no platforms connected in your workspace. Go to app.detrics.io and connect at least one data source.