Introduction
The Admin API enables you to programmatically manage API keys, track usage, and monitor billing for your Tinfoil account. This is particularly powerful when combined with the encrypted request proxying architecture, where you want to track usage for each of your individual users while maintaining end-to-end encryption to the Tinfoil enclave.Common Use Cases
Per-User Usage Tracking: The most common pattern is to create a separate Tinfoil API key for each of your users. When a user signs up for your service, use the Admin API to generate a dedicated API key for them and store it on your backend. Then, when proxying requests to Tinfoil, use that user’s specific API key. This allows you to query usage statistics per user using the Admin API’s?key= parameter.
Programmatic Key Management: Automate API key lifecycle management—create keys when users sign up, delete them when users leave, or set expiration dates and token limits based on your business logic.
Custom Dashboards: Build internal dashboards that display usage metrics, cost breakdowns by user or by model, and historical trends using the time-series endpoints.
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 all 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.
Response
Create API Key
Creates a new regular API key for token-based API access.
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
Per-User Usage Tracking
A common pattern for tracking usage on a per-user basis is to combine the Admin API with the encrypted request proxy architecture. Here’s how it works:Workflow
- User Signs Up: When a new user signs up for your service, use the Create API Key endpoint to generate a dedicated Tinfoil API key for them.
-
Store the Key: Save this API key on your backend, associated with the user’s account. You can use the
metadatafield to store your internal user ID for easy reference. -
Proxy Requests: When your user makes inference requests, your proxy server uses that user’s specific Tinfoil API key in the
Authorizationheader. The request body remains encrypted end-to-end from your user’s client to the Tinfoil enclave. - Track Usage: Query the Get Usage by Key endpoint with the user’s API key in the request body to retrieve usage and cost for that specific user.
Example: Creating a User-Specific Key
Example: Retrieving Usage for a Specific User
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:
1h- 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. This is the recommended approach for per-user usage tracking—create one API key per user and query their usage using this endpoint.
Query Parameters
Time period for usage statistics. If omitted, returns all-time usage. Valid values:
1h- 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.

