import { OpenRouter } from '@openrouter/sdk';
const openRouter = new OpenRouter({
apiKey: 'your-management-key', // Use your Management API key
});
// List the most recent 100 API keys
const keys = await openRouter.apiKeys.list();
// You can paginate using the offset parameter
const keysPage2 = await openRouter.apiKeys.list({ offset: 100 });
// Create a new API key
const newKey = await openRouter.apiKeys.create({
name: 'Customer Instance Key',
limit: 1000, // Optional credit limit
});
// Get a specific key
const keyHash = '<YOUR_KEY_HASH>';
const key = await openRouter.apiKeys.get(keyHash);
// Update a key
const updatedKey = await openRouter.apiKeys.update(keyHash, {
name: 'Updated Key Name',
disabled: true, // Optional: Disable the key
includeByokInLimit: false, // Optional: control BYOK usage in limit
limitReset: 'daily', // Optional: reset limit every day at midnight UTC
});
// Delete a key
await openRouter.apiKeys.delete(keyHash);