Prerequisites
- An OpenRouter management API key, which you can create on the Management API Keys page in OpenRouter (for organizations, only an Organization Admin can create one)
- A role in the Infisical project that lets you create dynamic secrets
If your management key has an expiration date, the dynamic secret stops working when the key expires. Before that date, create a new management key in the same OpenRouter organization and enter it in the dynamic secret. You can’t change the management key while the dynamic secret has active leases, so revoke them first.
Step 1: Create the dynamic secret
1
In your project, go to the environment and folder where you want the dynamic secret, then select Add New > Add Dynamic Secret.
2
Select OpenRouter.
3
Fill in the form:
How long a lease lasts if the person creating it doesn’t choose a TTL (for example,
1h).Your OpenRouter management API key. When you edit the dynamic secret, leave this blank to keep the current key.
The ID of the OpenRouter workspace to create API keys in. If you leave this blank, OpenRouter creates keys in the default workspace of the management key.
The most each API key can spend, in US dollars, as a number such as
10 or 2.5. If you leave this blank, the keys have no spending limit.How often the credit limit of each API key resets: Never, Daily, Weekly, or Monthly. OpenRouter resets limits at midnight UTC, and weeks run Monday through Sunday.
Whether usage through your own provider keys (BYOK) counts toward the credit limit.
The name each API key gets in OpenRouter, under Advanced. The default gives each key a random name that starts with
infisical-. You can use {{dynamicSecret.name}}, {{identity.name}}, {{unixTimestamp}}, and {{randomUsername}} to make the keys easier to find in OpenRouter.4
Select Submit.Before Infisical saves the dynamic secret, it checks that the management key works. If OpenRouter rejects the key, Infisical shows the error from OpenRouter and doesn’t save the dynamic secret.
Step 2: Create a lease
1
In the row for the dynamic secret, select Generate Lease.
2
Enter a Default TTL for the lease, then select Provision Lease.
3
Copy the values Infisical shows:
API_KEY: the OpenRouter API key, which starts withsk-or-v1-KEY_HASH: the ID OpenRouter uses for the key in its APIKEY_NAME: the name of the key in OpenRouter