APIKeys - TypeScript SDK
APIKeys - TypeScript SDK
APIKeys - TypeScript SDK
The TypeScript SDK and docs are currently in beta. Report issues on GitHub.
API key management endpoints
Get information on the API key associated with the current authentication session
1 import { OpenRouter } from "@openrouter/sdk"; 2 3 const openRouter = new OpenRouter({ 4 httpReferer: "<value>", 5 appTitle: "<value>", 6 appCategories: "<value>", 7 apiKey: process.env["OPENROUTER_API_KEY"] ?? "", 8 }); 9 10 async function run() { 11 const result = await openRouter.apiKeys.getCurrentKeyMetadata(); 12 13 console.log(result); 14 } 15 16 run();
The standalone function version of this method:
1 import { OpenRouterCore } from "@openrouter/sdk/core.js"; 2 import { apiKeysGetCurrentKeyMetadata } from "@openrouter/sdk/funcs/apiKeysGetCurrentKeyMetadata.js"; 3 4 // Use `OpenRouterCore` for best tree-shaking performance. 5 // You can create one instance of it to use across an application. 6 const openRouter = new OpenRouterCore({ 7 httpReferer: "<value>", 8 appTitle: "<value>", 9 appCategories: "<value>", 10 apiKey: process.env["OPENROUTER_API_KEY"] ?? "", 11 }); 12 13 async function run() { 14 const res = await apiKeysGetCurrentKeyMetadata(openRouter); 15 if (res.ok) { 16 const { value: result } = res; 17 console.log(result); 18 } else { 19 console.log("apiKeysGetCurrentKeyMetadata failed:", res.error); 20 } 21 } 22 23 run();
| Parameter | Type | Required | Description |
|---|---|---|---|
request | operations.GetCurrentKeyRequest | ✔️ | The request object to use for the request. |
options | RequestOptions | ➖ | Used to set various options for making HTTP requests. |
options.fetchOptions | RequestInit | ➖ | Options that are passed to the underlying HTTP request. This can be used to inject extra headers for examples. All Request options, except method and body, are allowed. |
options.retries | RetryConfig | ➖ | Enables retrying HTTP requests under certain failure conditions. |
Promise<operations.GetCurrentKeyResponse>
| Error Type | Status Code | Content Type |
|---|---|---|
| errors.UnauthorizedResponseError | 401 | application/json |
| errors.InternalServerResponseError | 500 | application/json |
| errors.OpenRouterDefaultError | 4XX, 5XX | */* |
List all API keys for the authenticated user. Management key required.
1 import { OpenRouter } from "@openrouter/sdk"; 2 3 const openRouter = new OpenRouter({ 4 httpReferer: "<value>", 5 appTitle: "<value>", 6 appCategories: "<value>", 7 apiKey: process.env["OPENROUTER_API_KEY"] ?? "", 8 }); 9 10 async function run() { 11 const result = await openRouter.apiKeys.list(); 12 13 console.log(result); 14 } 15 16 run();
The standalone function version of this method:
1 import { OpenRouterCore } from "@openrouter/sdk/core.js"; 2 import { apiKeysList } from "@openrouter/sdk/funcs/apiKeysList.js"; 3 4 // Use `OpenRouterCore` for best tree-shaking performance. 5 // You can create one instance of it to use across an application. 6 const openRouter = new OpenRouterCore({ 7 httpReferer: "<value>", 8 appTitle: "<value>", 9 appCategories: "<value>", 10 apiKey: process.env["OPENROUTER_API_KEY"] ?? "", 11 }); 12 13 async function run() { 14 const res = await apiKeysList(openRouter); 15 if (res.ok) { 16 const { value: result } = res; 17 console.log(result); 18 } else { 19 console.log("apiKeysList failed:", res.error); 20 } 21 } 22 23 run();
| Parameter | Type | Required | Description |
|---|---|---|---|
request | operations.ListRequest | ✔️ | The request object to use for the request. |
options | RequestOptions | ➖ | Used to set various options for making HTTP requests. |
options.fetchOptions | RequestInit | ➖ | Options that are passed to the underlying HTTP request. This can be used to inject extra headers for examples. All Request options, except method and body, are allowed. |
options.retries | RetryConfig | ➖ | Enables retrying HTTP requests under certain failure conditions. |
Promise<operations.ListResponse>
| Error Type | Status Code | Content Type |
|---|---|---|
| errors.UnauthorizedResponseError | 401 | application/json |
| errors.TooManyRequestsResponseError | 429 | application/json |
| errors.InternalServerResponseError | 500 | application/json |
| errors.OpenRouterDefaultError | 4XX, 5XX | */* |
Create a new API key for the authenticated user. Management key required.
1 import { OpenRouter } from "@openrouter/sdk"; 2 3 const openRouter = new OpenRouter({ 4 httpReferer: "<value>", 5 appTitle: "<value>", 6 appCategories: "<value>", 7 apiKey: process.env["OPENROUTER_API_KEY"] ?? "", 8 }); 9 10 async function run() { 11 const result = await openRouter.apiKeys.create({ 12 requestBody: { 13 expiresAt: new Date("2027-12-31T23:59:59Z"), 14 includeByokInLimit: true, 15 limit: 50, 16 limitReset: "monthly", 17 name: "My New API Key", 18 }, 19 }); 20 21 console.log(result); 22 } 23 24 run();
The standalone function version of this method:
1 import { OpenRouterCore } from "@openrouter/sdk/core.js"; 2 import { apiKeysCreate } from "@openrouter/sdk/funcs/apiKeysCreate.js"; 3 4 // Use `OpenRouterCore` for best tree-shaking performance. 5 // You can create one instance of it to use across an application. 6 const openRouter = new OpenRouterCore({ 7 httpReferer: "<value>", 8 appTitle: "<value>", 9 appCategories: "<value>", 10 apiKey: process.env["OPENROUTER_API_KEY"] ?? "", 11 }); 12 13 async function run() { 14 const res = await apiKeysCreate(openRouter, { 15 requestBody: { 16 expiresAt: new Date("2027-12-31T23:59:59Z"), 17 includeByokInLimit: true, 18 limit: 50, 19 limitReset: "monthly", 20 name: "My New API Key", 21 }, 22 }); 23 if (res.ok) { 24 const { value: result } = res; 25 console.log(result); 26 } else { 27 console.log("apiKeysCreate failed:", res.error); 28 } 29 } 30 31 run();
| Parameter | Type | Required | Description |
|---|---|---|---|
request | operations.CreateKeysRequest | ✔️ | The request object to use for the request. |
options | RequestOptions | ➖ | Used to set various options for making HTTP requests. |
options.fetchOptions | RequestInit | ➖ | Options that are passed to the underlying HTTP request. This can be used to inject extra headers for examples. All Request options, except method and body, are allowed. |
options.retries | RetryConfig | ➖ | Enables retrying HTTP requests under certain failure conditions. |
Promise<operations.CreateKeysResponse>
| Error Type | Status Code | Content Type |
|---|---|---|
| errors.BadRequestResponseError | 400 | application/json |
| errors.UnauthorizedResponseError | 401 | application/json |
| errors.ForbiddenResponseError | 403 | application/json |
| errors.TooManyRequestsResponseError | 429 | application/json |
| errors.InternalServerResponseError | 500 | application/json |
| errors.OpenRouterDefaultError | 4XX, 5XX | */* |
Delete an existing API key. Management key required.
1 import { OpenRouter } from "@openrouter/sdk"; 2 3 const openRouter = new OpenRouter({ 4 httpReferer: "<value>", 5 appTitle: "<value>", 6 appCategories: "<value>", 7 apiKey: process.env["OPENROUTER_API_KEY"] ?? "", 8 }); 9 10 async function run() { 11 const result = await openRouter.apiKeys.delete({ 12 hash: "f01d52606dc8f0a8303a7b5cc3fa07109c2e346cec7c0a16b40de462992ce943", 13 }); 14 15 console.log(result); 16 } 17 18 run();
The standalone function version of this method:
1 import { OpenRouterCore } from "@openrouter/sdk/core.js"; 2 import { apiKeysDelete } from "@openrouter/sdk/funcs/apiKeysDelete.js"; 3 4 // Use `OpenRouterCore` for best tree-shaking performance. 5 // You can create one instance of it to use across an application. 6 const openRouter = new OpenRouterCore({ 7 httpReferer: "<value>", 8 appTitle: "<value>", 9 appCategories: "<value>", 10 apiKey: process.env["OPENROUTER_API_KEY"] ?? "", 11 }); 12 13 async function run() { 14 const res = await apiKeysDelete(openRouter, { 15 hash: "f01d52606dc8f0a8303a7b5cc3fa07109c2e346cec7c0a16b40de462992ce943", 16 }); 17 if (res.ok) { 18 const { value: result } = res; 19 console.log(result); 20 } else { 21 console.log("apiKeysDelete failed:", res.error); 22 } 23 } 24 25 run();
| Parameter | Type | Required | Description |
|---|---|---|---|
request | operations.DeleteKeysRequest | ✔️ | The request object to use for the request. |
options | RequestOptions | ➖ | Used to set various options for making HTTP requests. |
options.fetchOptions | RequestInit | ➖ | Options that are passed to the underlying HTTP request. This can be used to inject extra headers for examples. All Request options, except method and body, are allowed. |
options.retries | RetryConfig | ➖ | Enables retrying HTTP requests under certain failure conditions. |
Promise<operations.DeleteKeysResponse>
| Error Type | Status Code | Content Type |
|---|---|---|
| errors.UnauthorizedResponseError | 401 | application/json |
| errors.NotFoundResponseError | 404 | application/json |
| errors.TooManyRequestsResponseError | 429 | application/json |
| errors.InternalServerResponseError | 500 | application/json |
| errors.OpenRouterDefaultError | 4XX, 5XX | */* |
Get a single API key by hash. Management key required.
1 import { OpenRouter } from "@openrouter/sdk"; 2 3 const openRouter = new OpenRouter({ 4 httpReferer: "<value>", 5 appTitle: "<value>", 6 appCategories: "<value>", 7 apiKey: process.env["OPENROUTER_API_KEY"] ?? "", 8 }); 9 10 async function run() { 11 const result = await openRouter.apiKeys.get({ 12 hash: "f01d52606dc8f0a8303a7b5cc3fa07109c2e346cec7c0a16b40de462992ce943", 13 }); 14 15 console.log(result); 16 } 17 18 run();
The standalone function version of this method:
1 import { OpenRouterCore } from "@openrouter/sdk/core.js"; 2 import { apiKeysGet } from "@openrouter/sdk/funcs/apiKeysGet.js"; 3 4 // Use `OpenRouterCore` for best tree-shaking performance. 5 // You can create one instance of it to use across an application. 6 const openRouter = new OpenRouterCore({ 7 httpReferer: "<value>", 8 appTitle: "<value>", 9 appCategories: "<value>", 10 apiKey: process.env["OPENROUTER_API_KEY"] ?? "", 11 }); 12 13 async function run() { 14 const res = await apiKeysGet(openRouter, { 15 hash: "f01d52606dc8f0a8303a7b5cc3fa07109c2e346cec7c0a16b40de462992ce943", 16 }); 17 if (res.ok) { 18 const { value: result } = res; 19 console.log(result); 20 } else { 21 console.log("apiKeysGet failed:", res.error); 22 } 23 } 24 25 run();
| Parameter | Type | Required | Description |
|---|---|---|---|
request | operations.GetKeyRequest | ✔️ | The request object to use for the request. |
options | RequestOptions | ➖ | Used to set various options for making HTTP requests. |
options.fetchOptions | RequestInit | ➖ | Options that are passed to the underlying HTTP request. This can be used to inject extra headers for examples. All Request options, except method and body, are allowed. |
options.retries | RetryConfig | ➖ | Enables retrying HTTP requests under certain failure conditions. |
Promise<operations.GetKeyResponse>
| Error Type | Status Code | Content Type |
|---|---|---|
| errors.UnauthorizedResponseError | 401 | application/json |
| errors.NotFoundResponseError | 404 | application/json |
| errors.TooManyRequestsResponseError | 429 | application/json |
| errors.InternalServerResponseError | 500 | application/json |
| errors.OpenRouterDefaultError | 4XX, 5XX | */* |
Update an existing API key. Management key required.
1 import { OpenRouter } from "@openrouter/sdk"; 2 3 const openRouter = new OpenRouter({ 4 httpReferer: "<value>", 5 appTitle: "<value>", 6 appCategories: "<value>", 7 apiKey: process.env["OPENROUTER_API_KEY"] ?? "", 8 }); 9 10 async function run() { 11 const result = await openRouter.apiKeys.update({ 12 hash: "f01d52606dc8f0a8303a7b5cc3fa07109c2e346cec7c0a16b40de462992ce943", 13 requestBody: { 14 disabled: false, 15 includeByokInLimit: true, 16 limit: 75, 17 limitReset: "daily", 18 name: "Updated API Key Name", 19 }, 20 }); 21 22 console.log(result); 23 } 24 25 run();
The standalone function version of this method:
1 import { OpenRouterCore } from "@openrouter/sdk/core.js"; 2 import { apiKeysUpdate } from "@openrouter/sdk/funcs/apiKeysUpdate.js"; 3 4 // Use `OpenRouterCore` for best tree-shaking performance. 5 // You can create one instance of it to use across an application. 6 const openRouter = new OpenRouterCore({ 7 httpReferer: "<value>", 8 appTitle: "<value>", 9 appCategories: "<value>", 10 apiKey: process.env["OPENROUTER_API_KEY"] ?? "", 11 }); 12 13 async function run() { 14 const res = await apiKeysUpdate(openRouter, { 15 hash: "f01d52606dc8f0a8303a7b5cc3fa07109c2e346cec7c0a16b40de462992ce943", 16 requestBody: { 17 disabled: false, 18 includeByokInLimit: true, 19 limit: 75, 20 limitReset: "daily", 21 name: "Updated API Key Name", 22 }, 23 }); 24 if (res.ok) { 25 const { value: result } = res; 26 console.log(result); 27 } else { 28 console.log("apiKeysUpdate failed:", res.error); 29 } 30 } 31 32 run();
| Parameter | Type | Required | Description |
|---|---|---|---|
request | operations.UpdateKeysRequest | ✔️ | The request object to use for the request. |
options | RequestOptions | ➖ | Used to set various options for making HTTP requests. |
options.fetchOptions | RequestInit | ➖ | Options that are passed to the underlying HTTP request. This can be used to inject extra headers for examples. All Request options, except method and body, are allowed. |
options.retries | RetryConfig | ➖ | Enables retrying HTTP requests under certain failure conditions. |
Promise<operations.UpdateKeysResponse>
| Error Type | Status Code | Content Type |
|---|---|---|
| errors.BadRequestResponseError | 400 | application/json |
| errors.UnauthorizedResponseError | 401 | application/json |
| errors.NotFoundResponseError | 404 | application/json |
| errors.TooManyRequestsResponseError | 429 | application/json |
| errors.InternalServerResponseError | 500 | application/json |
| errors.OpenRouterDefaultError | 4XX, 5XX | */* |