Introduction
The Admin API allows you to programmatically manage your account’s resources, including API keys, usage metrics, and billing. This provides programmatic control over administrative tasks that would otherwise require manual configuration in the Tinfoil Dashboard.Common Use Cases
- Automating key management: Create, rotate, or delete API keys programmatically, and set expiration dates or token limits based on your business logic.
- Building custom dashboards: Display usage metrics, cost breakdowns by model, and historical trends using the billing and time-series endpoints.
- Monitoring usage: Query aggregated or per-key usage statistics to track costs and token consumption.
Authentication
Admin API keys provide programmatic access to your account resources. Admin keys are prefixed withadmin_ and must be included in the Authorization header as a Bearer token.
Need to create an admin API key? Follow our step-by-step guide: Getting a Tinfoil Admin Key
Available Endpoints
Admin API keys can access the following endpoints:API Key Management
GET /api/keys- List API keysPOST /api/keys- Create a new API keyDELETE /api/keys/:key- Delete an API keyPOST /api/keys/rename- Rename an API key
Billing & Usage
GET /api/billing/usage- Get aggregated usage statistics for all keysPOST /api/billing/usage/key- Get usage statistics for a specific keyGET /api/billing/time-series- Get time series dataGET /api/billing/transactions- Get transaction history
API Key Management
List API Keys
Returns all regular (non-admin) API keys for the authenticated user.
Example Request
Response
Create API Key
Creates a new regular API key for token-based API access. Requires an active API billing subscription.
Request Body
Name for the API key. Must contain only alphanumeric characters, hyphens, underscores, spaces, and periods.
ISO 8601 timestamp when the key should expire. If not provided, the key doesn’t expire.
Maximum number of tokens this key can use. If not provided, no limit is enforced.
Custom metadata to attach to the key. Maximum size: 5KB.
Example Request
Response
Delete API Key
Deletes a specific API key owned by the user.
Path Parameters
The API key to delete (e.g.,
tk_abc123...)Example Request
Response
Rename API Key
Renames an existing API key.
Request Body
The API key to rename.
New name for the API key. Must contain only alphanumeric characters, hyphens, underscores, spaces, and periods.
Example Request
Response
Billing & Usage
Get Usage Statistics
Retrieves aggregated token usage statistics for all keys for the specified time period.
Query Parameters
Time period for usage statistics. If omitted, returns all-time usage. Valid values:
5m- Last 5 minutes15m- Last 15 minutes30m- Last 30 minutes1h- Last hour24h- Last 24 hours7d- Last 7 days30d- Last 30 days60d- Last 60 days90d- Last 90 days
Example Request
Response
Get Usage by Key
Retrieves token usage statistics for a specific API key owned by the authenticated user.
Query Parameters
Time period for usage statistics. If omitted, returns all-time usage. Valid values:
5m- Last 5 minutes15m- Last 15 minutes30m- Last 30 minutes1h- Last hour24h- Last 24 hours7d- Last 7 days30d- Last 30 days60d- Last 60 days90d- Last 90 days
Request Body
The API key to query usage for (e.g.,
tk_abc123...).Example Request
Response
Get Time Series Data
Retrieves time-series data for token usage over the specified period.
Query Parameters
Time period for the time series. Valid values:
5m- Last 5 minutes15m- Last 15 minutes30m- Last 30 minutes1h- Last hour24h- Last 24 hours7d- Last 7 days30d- Last 30 days60d- Last 60 days90d- Last 90 days
Example Request
Response
Get Transaction History
Retrieves the transaction history including invoices and charges.
Example Request
Response
Error Responses
Example error response:| Code | HTTP Status | Description |
|---|---|---|
UNAUTHORIZED | 401 | Invalid or expired admin API key |
BAD_REQUEST | 400 | Invalid request parameters |
NOT_FOUND | 404 | Resource not found |
PAYMENT_REQUIRED | 402 | Active subscription required |
INTERNAL_ERROR | 500 | Server error |

