const MANAGEMENT_API_KEY = 'your-management-key';
const BASE_URL = 'https://openrouter.ai/api/v1/keys';
// List the most recent 100 API keys
const listKeys = await fetch(BASE_URL, {
headers: {
Authorization: `Bearer ${MANAGEMENT_API_KEY}`,
'Content-Type': 'application/json',
},
});
// You can paginate using the `offset` query parameter
const listKeys = await fetch(`${BASE_URL}?offset=100`, {
headers: {
Authorization: `Bearer ${MANAGEMENT_API_KEY}`,
'Content-Type': 'application/json',
},
});
// Create a new API key
const createKey = await fetch(`${BASE_URL}`, {
method: 'POST',
headers: {
Authorization: `Bearer ${MANAGEMENT_API_KEY}`,
'Content-Type': 'application/json',
},
body: JSON.stringify({
name: 'Customer Instance Key',
limit: 1000, // Optional credit limit
}),
});
// Get a specific key
const keyHash = '<YOUR_KEY_HASH>';
const getKey = await fetch(`${BASE_URL}/${keyHash}`, {
headers: {
Authorization: `Bearer ${MANAGEMENT_API_KEY}`,
'Content-Type': 'application/json',
},
});
// Update a key
const updateKey = await fetch(`${BASE_URL}/${keyHash}`, {
method: 'PATCH',
headers: {
Authorization: `Bearer ${MANAGEMENT_API_KEY}`,
'Content-Type': 'application/json',
},
body: JSON.stringify({
name: 'Updated Key Name',
disabled: true, // Optional: Disable the key
include_byok_in_limit: false, // Optional: control BYOK usage in limit
limit_reset: 'daily', // Optional: reset limit every day at midnight UTC
}),
});
// Delete a key
const deleteKey = await fetch(`${BASE_URL}/${keyHash}`, {
method: 'DELETE',
headers: {
Authorization: `Bearer ${MANAGEMENT_API_KEY}`,
'Content-Type': 'application/json',
},
});