OpenRouter Integration
Connect your OpenRouter account to track per-model AI costs and token usage in Grafient.
Overview
Grafient uses a Management API key to ingest daily cost and usage data through the OpenRouter Activity API. This integration tracks actual USD spend across every model you use through OpenRouter, with per-model breakdowns, token counts, and request counts for up to 30 days of history.
OpenRouter acts as a multi-provider router — your costs may span models from OpenAI, Anthropic, Google, Meta, and others, all tracked in one place.
Prerequisites
Before you begin, make sure you have:
- An OpenRouter account with credits loaded.
- A Management API key — regular inference keys (
sk-or-...) cannot access the Activity API. - A Grafient account on the Free, Pro, or Ultimate plan.
Permissions and Security
OpenRouter has two key types:
- Regular (inference) keys — used to make LLM completions. These start with
sk-or-and cannot access the Activity API. - Management keys — used for admin and analytics. These can access usage and credit data but cannot make completions.
Grafient requires a Management key. It only reads the following data:
- Daily usage activity (cost, tokens, requests per model)
- Key metadata for validation
Grafient will never make inference requests, modify your account, or access prompt/completion content. Your API key is encrypted with AES-256-GCM before storage and is never exposed after the initial connection.
Create a Connection
Step 1: Create a Management API Key in OpenRouter
- Log in to openrouter.ai.
- Navigate to Settings > Keys or visit openrouter.ai/settings/keys.
- Click Create Management Key.
- Give your key a descriptive name, such as
Grafient Integration. - Copy the generated key immediately.
Management keys are distinct from inference keys. Make sure you create a Management key, not a regular API key. The key is only shown once — store it securely until you complete the next step.
Step 2: Add the Key to Grafient
- In Grafient, navigate to the Integrations page from the sidebar.
- Click Add Integration.
- Select OpenRouter as the provider.
- Enter a label to identify this integration (e.g.,
Production — OpenRouter). If left blank, a default label is generated for you. - Paste the Management API key you copied in Step 1.
- Click Test Connection — a green checkmark confirms the key is valid and is a Management key.
- Click Add Integration to save.
What Happens Next
Once you add the integration, Grafient will:
- Validate your API key by checking that it is a Management key via the OpenRouter Auth endpoint.
- Backfill historical costs — up to 30 days of activity data (this is the maximum OpenRouter provides).
- Sync daily via an automated job at 6 AM UTC to pull the previous day's finalized cost data.
Your costs will appear on the Dashboard within a few seconds of the initial sync. You can also click Force Sync on the integration card at any time to pull the latest data.
Data Collected
| Data Point | Description |
|---|---|
| Daily cost (USD) | Total spend per day, broken down by model |
| Model breakdown | Cost attributed to each model routed through OpenRouter (e.g., openai/gpt-4.1, anthropic/claude-sonnet-4) |
| Prompt tokens | Input token consumption per model |
| Completion tokens | Output token consumption per model |
| Request count | Number of API requests per model |
OpenRouter provides up to 30 days of historical activity data. Older data is not available through the API.
API Endpoints Used
| Endpoint | Purpose |
|---|---|
GET /api/v1/auth/key | Validate key and confirm it is a Management key |
GET /api/v1/activity | Daily per-model usage data (cost, tokens, requests) |
Data Freshness
OpenRouter activity data is typically available for completed UTC days. The daily cron sync at 6 AM UTC captures the previous day's finalized data.
Troubleshooting
"Test Connection" fails
- Verify the key type: You must use a Management key, not a regular inference key. Regular keys start with
sk-or-and will be rejected. Management keys are created separately in your OpenRouter settings. - Check your account: Make sure your OpenRouter account is active and has been used for inference at least once.
- Network issues: Confirm that
openrouter.aiis reachable from your environment.
No cost data appears after sync
- Check for recent usage: If there has been no inference usage in the last 30 days, there will be no activity data to display.
- Wait for data availability: Activity data covers completed UTC days. Today's usage will appear tomorrow.
- Try Force Sync: Click the refresh icon on your integration card to trigger a manual sync.
Integration shows an error status
- Revoked key: If the Management key was deleted or rotated in OpenRouter, the integration will fail. Remove the integration and add a new one with the updated key.
- API changes: If OpenRouter changes their API, syncs may fail temporarily. Grafient monitors for API shape changes and will update the integration accordingly.