APIKeys - TypeScript SDK
The TypeScript SDK and docs are currently in beta. Report issues on GitHub.
Overview
API key management endpoints
Available Operations
- list - List API keys
- create - Create a new API key
- update - Update an API key
- delete - Delete an API key
- get - Get a single API key
- getCurrentKeyMetadata - Get current API key
list
List all API keys for the authenticated user. Management key required.
Example Usage
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();
Standalone function
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();
Parameters
| 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. |
Response
Promise<operations.ListResponse>
Errors
| 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
Create a new API key for the authenticated user. Management key required.
Example Usage
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 name: "My New API Key", 14 }, 15 }); 16 17 console.log(result); 18 } 19 20 run();
Standalone function
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 name: "My New API Key", 17 }, 18 }); 19 if (res.ok) { 20 const { value: result } = res; 21 console.log(result); 22 } else { 23 console.log("apiKeysCreate failed:", res.error); 24 } 25 } 26 27 run();
Parameters
| 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. |
Response
Promise<operations.CreateKeysResponse>
Errors
| Error Type | Status Code | Content Type |
|---|---|---|
| errors.BadRequestResponseError | 400 | application/json |
| errors.UnauthorizedResponseError | 401 | application/json |
| errors.TooManyRequestsResponseError | 429 | application/json |
| errors.InternalServerResponseError | 500 | application/json |
| errors.OpenRouterDefaultError | 4XX, 5XX | */* |
update
Update an existing API key. Management key required.
Example Usage
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 }); 15 16 console.log(result); 17 } 18 19 run();
Standalone function
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 }); 18 if (res.ok) { 19 const { value: result } = res; 20 console.log(result); 21 } else { 22 console.log("apiKeysUpdate failed:", res.error); 23 } 24 } 25 26 run();
Parameters
| 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. |
Response
Promise<operations.UpdateKeysResponse>
Errors
| 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 | */* |
delete
Delete an existing API key. Management key required.
Example Usage
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();
Standalone function
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();
Parameters
| 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. |
Response
Promise<operations.DeleteKeysResponse>
Errors
| 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
Get a single API key by hash. Management key required.
Example Usage
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();
Standalone function
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();
Parameters
| 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. |
Response
Promise<operations.GetKeyResponse>
Errors
| 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 | */* |
getCurrentKeyMetadata
Get information on the API key associated with the current authentication session
Example Usage
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();
Standalone function
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();
Parameters
| 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. |
Response
Promise<operations.GetCurrentKeyResponse>
Errors
| Error Type | Status Code | Content Type |
|---|---|---|
| errors.UnauthorizedResponseError | 401 | application/json |
| errors.InternalServerResponseError | 500 | application/json |
| errors.OpenRouterDefaultError | 4XX, 5XX | */* |