API Key Management
Use this key to authenticate API requests from n8n and other services.
Login Required
You need to be logged in to view and manage your API key. Please log in or create an account to get started.
Track AI Token Usage from n8n
Custom n8n Nodes Coming Soon
We're developingcustom n8n nodesthat will make token tracking even easier. Until then, use the HTTP Request method below.
How to Track Token Usage
After any AI node in your n8n workflow (OpenAI, Anthropic, Google, etc.), add an HTTP Request node to send token usage data to this platform.
Quick Setup: Use the Connect to n8n Button
First, enable dashboard editing by clicking the toggle button at the top of the workflow dashboard. Then, click the Connect to n8n button to access pre-configured HTTP Request node code with your API key already filled in. Click to copy and paste it into your n8n workflow - no manual configuration needed
Step 1: Add HTTP Request Node
In your n8n workflow, after your AI node, add anHTTP Requestnode.
Step 2: Configure the HTTP Request
POSThttps://invokati.com/api/token-usageSelect "Header Auth" and add:
X-API-KeyStep 3: Set the JSON Body
In the HTTP Request node, setBody Content TypetoJSONand use this structure:
{
"n8n_base_url": "{{ $env.WEBHOOK_URL.split('/webhook')[0] }}",
"workflow_id": "{{ $workflow.id }}",
"execution_id": "{{ $execution.id }}",
"model_id": "gpt-4",
"input_tokens": {{ $json.usage.prompt_tokens }},
"output_tokens": {{ $json.usage.completion_tokens }}
}Custom/Self-Hosted n8n Installations:
If your self-hosted n8n instance doesn't have the $env.WEBHOOK_URL environment variable set, simply replace the n8n_base_url value with your full n8n installation URL (e.g., "https://n8n.yourdomain.com").
Adjust for Your AI Provider:
- OpenAI:
$json.usage.prompt_tokensand$json.usage.completion_tokens - Anthropic:
$json.usage.input_tokensand$json.usage.output_tokens - Google:
$json.usageMetadata.promptTokenCountand$json.usageMetadata.candidatesTokenCount - Other providers: Check the response structure from your AI node
Step 4: Field Reference
| Field | Required | Description | Example |
|---|---|---|---|
| n8n_base_url | Yes | Base URL of your n8n instance | {{$env.WEBHOOK_URL.split('/webhook')[0] }} |
| workflow_id | Yes | n8n workflow identifier | {{ $workflow.id }} |
| execution_id | Yes | n8n execution identifier | {{ $execution.id }} |
| model_id | Yes | AI model name | "gpt-4", "claude-3-opus" |
| input_tokens | Yes | Number of input tokens | 1500 |
| output_tokens | Yes | Number of output tokens | 800 |
Step 5: Example Response
When successful, you'll receive a response like this:
{
"status": "success",
"message": "Token usage recorded successfully",
"id": "259",
"data": {
"workflow_id": "b9NLgJV0oXIpXSsr",
"execution_id": "551",
"installtion_id": "913",
"model_id": "gpt-4",
"input_tokens": 399,
"output_tokens": 288,
"total_tokens": 687,
"input_cost": 0.01197,
"output_cost": 0.01728,
"total_cost": 0.02925,
"model_found": true,
"model_label": "GPT-4"
}
}
Complete Example Workflow
Here's a complete example of how your n8n workflow should look:
- 1Trigger Node- Webhook, Schedule, etc.
- 2AI Node- OpenAI, Anthropic, Google AI, etc.
- 3HTTP Request Node- Send token usage to this platform
- 4Continue Workflow- Process AI response, send results, etc.
Pro Tip
Set the HTTP Request node to "Continue On Fail" so that if token tracking fails, your workflow still completes successfully.
Set Up n8n Webhook Trigger
Quick Setup: Use the Connect to n8n Button
First, enable dashboard editing by clicking the toggle button at the top of the workflow dashboard. Then, click the Connect to n8n button to find a Copy Trigger Node button that copies a fully pre-configured webhook node to your clipboard. Simply paste it into your n8n workflow editor - no manual configuration needed
Quick Setup (Recommended)
Step 1: Copy Pre-Configured Node from Connect to n8n Menu
Enable dashboard editing by clicking the toggle button at the top of the workflow dashboard, then click the Connect to n8n button and click the Copy Trigger Node button. This copies a fully configured webhook node with your unique workflow path to your clipboard.
Step 2: Paste into n8n Workflow
Open your n8n workflow editor and press Ctrl+V (or ⌘+V on Mac) to paste the webhook node.
Step 3: Configure Test or Production Mode
While editing your dashboard layout, hover over the trigger widget and click the gear icon to access settings where you can toggle between test and production modes.
Use while building your workflow. Click "Listen for test event" in n8n to see incoming data in real-time.
Once ready, toggle to production mode and activate your workflow in n8n for live events.
Step 4: Activate Workflow
When using production mode, ensure your workflow is Active in n8n (toggle the switch in the top-right corner).
Manual Setup (Alternative)
If you prefer to configure the webhook manually, follow these steps:
1. Add Webhook Node
In your n8n canvas, click the + icon and search for Webhook.
2. Configure Settings
POSTinvokati-trigger/[installation_id]/[workflow_id]Use the unique path shown in your dashboard trigger widget.
ImmediatelyThis ensures the sender receives an instant 200 OK response.
3. Copy Webhook URL
Copy the webhook URL from n8n (either test or production) and use it in your dashboard trigger settings.
Pro Tip
The quick copy/paste method is recommended as it automatically configures all settings correctly, including the unique path for your workflow.
Help & Feedback
We'd love to hear from you