APIKeys - TypeScript SDK
The TypeScript SDK and docs are currently in beta. Report issues on GitHub.
(apiKeys)
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 API keys
Example Usage
1 import { OpenRouter } from "@openrouter/sdk"; 2 3 const openRouter = new OpenRouter({ 4 apiKey: process.env["OPENROUTER_API_KEY"] ?? "", 5 }); 6 7 async function run() { 8 const result = await openRouter.apiKeys.list(); 9 10 console.log(result); 11 } 12 13 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 apiKey: process.env["OPENROUTER_API_KEY"] ?? "", 8 }); 9 10 async function run() { 11 const res = await apiKeysList(openRouter); 12 if (res.ok) { 13 const { value: result } = res; 14 console.log(result); 15 } else { 16 console.log("apiKeysList failed:", res.error); 17 } 18 } 19 20 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
Example Usage
1 import { OpenRouter } from "@openrouter/sdk"; 2 3 const openRouter = new OpenRouter({ 4 apiKey: process.env["OPENROUTER_API_KEY"] ?? "", 5 }); 6 7 async function run() { 8 const result = await openRouter.apiKeys.create({ 9 name: "My New API Key", 10 }); 11 12 console.log(result); 13 } 14 15 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 apiKey: process.env["OPENROUTER_API_KEY"] ?? "", 8 }); 9 10 async function run() { 11 const res = await apiKeysCreate(openRouter, { 12 name: "My New API Key", 13 }); 14 if (res.ok) { 15 const { value: result } = res; 16 console.log(result); 17 } else { 18 console.log("apiKeysCreate failed:", res.error); 19 } 20 } 21 22 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 API key
Example Usage
1 import { OpenRouter } from "@openrouter/sdk"; 2 3 const openRouter = new OpenRouter({ 4 apiKey: process.env["OPENROUTER_API_KEY"] ?? "", 5 }); 6 7 async function run() { 8 const result = await openRouter.apiKeys.update({ 9 hash: "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", 10 requestBody: {}, 11 }); 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 { 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 apiKey: process.env["OPENROUTER_API_KEY"] ?? "", 8 }); 9 10 async function run() { 11 const res = await apiKeysUpdate(openRouter, { 12 hash: "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", 13 requestBody: {}, 14 }); 15 if (res.ok) { 16 const { value: result } = res; 17 console.log(result); 18 } else { 19 console.log("apiKeysUpdate failed:", res.error); 20 } 21 } 22 23 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 API key
Example Usage
1 import { OpenRouter } from "@openrouter/sdk"; 2 3 const openRouter = new OpenRouter({ 4 apiKey: process.env["OPENROUTER_API_KEY"] ?? "", 5 }); 6 7 async function run() { 8 const result = await openRouter.apiKeys.delete({ 9 hash: "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", 10 }); 11 12 console.log(result); 13 } 14 15 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 apiKey: process.env["OPENROUTER_API_KEY"] ?? "", 8 }); 9 10 async function run() { 11 const res = await apiKeysDelete(openRouter, { 12 hash: "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", 13 }); 14 if (res.ok) { 15 const { value: result } = res; 16 console.log(result); 17 } else { 18 console.log("apiKeysDelete failed:", res.error); 19 } 20 } 21 22 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
Example Usage
1 import { OpenRouter } from "@openrouter/sdk"; 2 3 const openRouter = new OpenRouter({ 4 apiKey: process.env["OPENROUTER_API_KEY"] ?? "", 5 }); 6 7 async function run() { 8 const result = await openRouter.apiKeys.get({ 9 hash: "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", 10 }); 11 12 console.log(result); 13 } 14 15 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 apiKey: process.env["OPENROUTER_API_KEY"] ?? "", 8 }); 9 10 async function run() { 11 const res = await apiKeysGet(openRouter, { 12 hash: "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", 13 }); 14 if (res.ok) { 15 const { value: result } = res; 16 console.log(result); 17 } else { 18 console.log("apiKeysGet failed:", res.error); 19 } 20 } 21 22 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 apiKey: process.env["OPENROUTER_API_KEY"] ?? "", 5 }); 6 7 async function run() { 8 const result = await openRouter.apiKeys.getCurrentKeyMetadata(); 9 10 console.log(result); 11 } 12 13 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 apiKey: process.env["OPENROUTER_API_KEY"] ?? "", 8 }); 9 10 async function run() { 11 const res = await apiKeysGetCurrentKeyMetadata(openRouter); 12 if (res.ok) { 13 const { value: result } = res; 14 console.log(result); 15 } else { 16 console.log("apiKeysGetCurrentKeyMetadata failed:", res.error); 17 } 18 } 19 20 run();
Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
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 | */* |