> ## Documentation Index > Fetch the complete documentation index at: https://openrouter.ai/docs/llms.txt > Use this file to discover all available pages before exploring further. # APIKeys > API key management endpoints ## Overview API key management endpoints ### Available Operations * [getCurrentKeyMetadata](#getcurrentkeymetadata) - Get current API key * [list](#list) - List API keys * [create](#create) - Create a new API key * [delete](#delete) - Delete an API key * [get](#get) - Get a single API key * [update](#update) - Update an API key ## getCurrentKeyMetadata Get information on the API key associated with the current authentication session ### Example Usage ```typescript theme={null} import { OpenRouter } from "@openrouter/sdk"; const openRouter = new OpenRouter({ httpReferer: "", appTitle: "", appCategories: "", apiKey: process.env["OPENROUTER_API_KEY"] ?? "", }); async function run() { const result = await openRouter.apiKeys.getCurrentKeyMetadata(); console.log(result); } run(); ``` ### Standalone function The standalone function version of this method: ```typescript theme={null} import { OpenRouterCore } from "@openrouter/sdk/core.js"; import { apiKeysGetCurrentKeyMetadata } from "@openrouter/sdk/funcs/apiKeysGetCurrentKeyMetadata.js"; // Use `OpenRouterCore` for best tree-shaking performance. // You can create one instance of it to use across an application. const openRouter = new OpenRouterCore({ httpReferer: "", appTitle: "", appCategories: "", apiKey: process.env["OPENROUTER_API_KEY"] ?? "", }); async function run() { const res = await apiKeysGetCurrentKeyMetadata(openRouter); if (res.ok) { const { value: result } = res; console.log(result); } else { console.log("apiKeysGetCurrentKeyMetadata failed:", res.error); } } run(); ``` ### Parameters | Parameter | Type | Required | Description | | ---------------------- | --------------------------------------------------------------------------------------- | -------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | | `request` | [operations.GetCurrentKeyRequest](../../models/operations/getcurrentkeyrequest.mdx) | :heavy\_check\_mark: | The request object to use for the request. | | `options` | RequestOptions | :heavy\_minus\_sign: | Used to set various options for making HTTP requests. | | `options.fetchOptions` | [RequestInit](https://developer.mozilla.org/en-US/docs/Web/API/Request/Request#options) | :heavy\_minus\_sign: | 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](../../lib/utils/retryconfig.mdx) | :heavy\_minus\_sign: | Enables retrying HTTP requests under certain failure conditions. | ### Response **Promise\<[operations.GetCurrentKeyResponse](../../models/operations/getcurrentkeyresponse.mdx)>** ### Errors | Error Type | Status Code | Content Type | | ---------------------------------- | ----------- | ---------------- | | errors.UnauthorizedResponseError | 401 | application/json | | errors.InternalServerResponseError | 500 | application/json | | errors.OpenRouterDefaultError | 4XX, 5XX | \*/\* | ## list List all API keys for the authenticated user. [Management key](/docs/client-sdks/typescript/docs/guides/overview/auth/management-api-keys) required. ### Example Usage ```typescript theme={null} import { OpenRouter } from "@openrouter/sdk"; const openRouter = new OpenRouter({ httpReferer: "", appTitle: "", appCategories: "", apiKey: process.env["OPENROUTER_API_KEY"] ?? "", }); async function run() { const result = await openRouter.apiKeys.list(); console.log(result); } run(); ``` ### Standalone function The standalone function version of this method: ```typescript theme={null} import { OpenRouterCore } from "@openrouter/sdk/core.js"; import { apiKeysList } from "@openrouter/sdk/funcs/apiKeysList.js"; // Use `OpenRouterCore` for best tree-shaking performance. // You can create one instance of it to use across an application. const openRouter = new OpenRouterCore({ httpReferer: "", appTitle: "", appCategories: "", apiKey: process.env["OPENROUTER_API_KEY"] ?? "", }); async function run() { const res = await apiKeysList(openRouter); if (res.ok) { const { value: result } = res; console.log(result); } else { console.log("apiKeysList failed:", res.error); } } run(); ``` ### Parameters | Parameter | Type | Required | Description | | ---------------------- | --------------------------------------------------------------------------------------- | -------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | | `request` | [operations.ListRequest](../../models/operations/listrequest.mdx) | :heavy\_check\_mark: | The request object to use for the request. | | `options` | RequestOptions | :heavy\_minus\_sign: | Used to set various options for making HTTP requests. | | `options.fetchOptions` | [RequestInit](https://developer.mozilla.org/en-US/docs/Web/API/Request/Request#options) | :heavy\_minus\_sign: | 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](../../lib/utils/retryconfig.mdx) | :heavy\_minus\_sign: | Enables retrying HTTP requests under certain failure conditions. | ### Response **Promise\<[operations.ListResponse](../../models/operations/listresponse.mdx)>** ### 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 | \*/\* | ## create Create a new API key for the authenticated user. The plaintext `key` is returned only in this response. Treat it as a write-only, sensitive value; it cannot be retrieved later. Authenticate with a [management key](/docs/client-sdks/typescript/docs/guides/overview/auth/management-api-keys). The optional `external` object associates the key with a partner-defined user and lookup key. ### Example Usage ```typescript theme={null} import { OpenRouter } from "@openrouter/sdk"; const openRouter = new OpenRouter({ httpReferer: "", appTitle: "", appCategories: "", apiKey: process.env["OPENROUTER_API_KEY"] ?? "", }); async function run() { const result = await openRouter.apiKeys.create({ requestBody: { expiresAt: new Date("2027-12-31T23:59:59Z"), includeByokInLimit: true, limit: 50, limitReset: "monthly", name: "My New API Key", }, }); console.log(result); } run(); ``` ### Standalone function The standalone function version of this method: ```typescript theme={null} import { OpenRouterCore } from "@openrouter/sdk/core.js"; import { apiKeysCreate } from "@openrouter/sdk/funcs/apiKeysCreate.js"; // Use `OpenRouterCore` for best tree-shaking performance. // You can create one instance of it to use across an application. const openRouter = new OpenRouterCore({ httpReferer: "", appTitle: "", appCategories: "", apiKey: process.env["OPENROUTER_API_KEY"] ?? "", }); async function run() { const res = await apiKeysCreate(openRouter, { requestBody: { expiresAt: new Date("2027-12-31T23:59:59Z"), includeByokInLimit: true, limit: 50, limitReset: "monthly", name: "My New API Key", }, }); if (res.ok) { const { value: result } = res; console.log(result); } else { console.log("apiKeysCreate failed:", res.error); } } run(); ``` ### Parameters | Parameter | Type | Required | Description | | ---------------------- | --------------------------------------------------------------------------------------- | -------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | | `request` | [operations.CreateKeysRequest](../../models/operations/createkeysrequest.mdx) | :heavy\_check\_mark: | The request object to use for the request. | | `options` | RequestOptions | :heavy\_minus\_sign: | Used to set various options for making HTTP requests. | | `options.fetchOptions` | [RequestInit](https://developer.mozilla.org/en-US/docs/Web/API/Request/Request#options) | :heavy\_minus\_sign: | 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](../../lib/utils/retryconfig.mdx) | :heavy\_minus\_sign: | Enables retrying HTTP requests under certain failure conditions. | ### Response **Promise\<[operations.CreateKeysResponse](../../models/operations/createkeysresponse.mdx)>** ### Errors | 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 Delete an existing API key. Authenticate with a [management key](/docs/client-sdks/typescript/docs/guides/overview/auth/management-api-keys). ### Example Usage ```typescript theme={null} import { OpenRouter } from "@openrouter/sdk"; const openRouter = new OpenRouter({ httpReferer: "", appTitle: "", appCategories: "", apiKey: process.env["OPENROUTER_API_KEY"] ?? "", }); async function run() { const result = await openRouter.apiKeys.delete({ hash: "f01d52606dc8f0a8303a7b5cc3fa07109c2e346cec7c0a16b40de462992ce943", }); console.log(result); } run(); ``` ### Standalone function The standalone function version of this method: ```typescript theme={null} import { OpenRouterCore } from "@openrouter/sdk/core.js"; import { apiKeysDelete } from "@openrouter/sdk/funcs/apiKeysDelete.js"; // Use `OpenRouterCore` for best tree-shaking performance. // You can create one instance of it to use across an application. const openRouter = new OpenRouterCore({ httpReferer: "", appTitle: "", appCategories: "", apiKey: process.env["OPENROUTER_API_KEY"] ?? "", }); async function run() { const res = await apiKeysDelete(openRouter, { hash: "f01d52606dc8f0a8303a7b5cc3fa07109c2e346cec7c0a16b40de462992ce943", }); if (res.ok) { const { value: result } = res; console.log(result); } else { console.log("apiKeysDelete failed:", res.error); } } run(); ``` ### Parameters | Parameter | Type | Required | Description | | ---------------------- | --------------------------------------------------------------------------------------- | -------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | | `request` | [operations.DeleteKeysRequest](../../models/operations/deletekeysrequest.mdx) | :heavy\_check\_mark: | The request object to use for the request. | | `options` | RequestOptions | :heavy\_minus\_sign: | Used to set various options for making HTTP requests. | | `options.fetchOptions` | [RequestInit](https://developer.mozilla.org/en-US/docs/Web/API/Request/Request#options) | :heavy\_minus\_sign: | 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](../../lib/utils/retryconfig.mdx) | :heavy\_minus\_sign: | Enables retrying HTTP requests under certain failure conditions. | ### Response **Promise\<[operations.DeleteKeysResponse](../../models/operations/deletekeysresponse.mdx)>** ### 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](/docs/client-sdks/typescript/docs/guides/overview/auth/management-api-keys) required. ### Example Usage ```typescript theme={null} import { OpenRouter } from "@openrouter/sdk"; const openRouter = new OpenRouter({ httpReferer: "", appTitle: "", appCategories: "", apiKey: process.env["OPENROUTER_API_KEY"] ?? "", }); async function run() { const result = await openRouter.apiKeys.get({ hash: "f01d52606dc8f0a8303a7b5cc3fa07109c2e346cec7c0a16b40de462992ce943", }); console.log(result); } run(); ``` ### Standalone function The standalone function version of this method: ```typescript theme={null} import { OpenRouterCore } from "@openrouter/sdk/core.js"; import { apiKeysGet } from "@openrouter/sdk/funcs/apiKeysGet.js"; // Use `OpenRouterCore` for best tree-shaking performance. // You can create one instance of it to use across an application. const openRouter = new OpenRouterCore({ httpReferer: "", appTitle: "", appCategories: "", apiKey: process.env["OPENROUTER_API_KEY"] ?? "", }); async function run() { const res = await apiKeysGet(openRouter, { hash: "f01d52606dc8f0a8303a7b5cc3fa07109c2e346cec7c0a16b40de462992ce943", }); if (res.ok) { const { value: result } = res; console.log(result); } else { console.log("apiKeysGet failed:", res.error); } } run(); ``` ### Parameters | Parameter | Type | Required | Description | | ---------------------- | --------------------------------------------------------------------------------------- | -------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | | `request` | [operations.GetKeyRequest](../../models/operations/getkeyrequest.mdx) | :heavy\_check\_mark: | The request object to use for the request. | | `options` | RequestOptions | :heavy\_minus\_sign: | Used to set various options for making HTTP requests. | | `options.fetchOptions` | [RequestInit](https://developer.mozilla.org/en-US/docs/Web/API/Request/Request#options) | :heavy\_minus\_sign: | 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](../../lib/utils/retryconfig.mdx) | :heavy\_minus\_sign: | Enables retrying HTTP requests under certain failure conditions. | ### Response **Promise\<[operations.GetKeyResponse](../../models/operations/getkeyresponse.mdx)>** ### 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 | \*/\* | ## update Update an existing API key. Authenticate with a [management key](/docs/client-sdks/typescript/docs/guides/overview/auth/management-api-keys). ### Example Usage ```typescript theme={null} import { OpenRouter } from "@openrouter/sdk"; const openRouter = new OpenRouter({ httpReferer: "", appTitle: "", appCategories: "", apiKey: process.env["OPENROUTER_API_KEY"] ?? "", }); async function run() { const result = await openRouter.apiKeys.update({ hash: "f01d52606dc8f0a8303a7b5cc3fa07109c2e346cec7c0a16b40de462992ce943", requestBody: { disabled: false, includeByokInLimit: true, limit: 75, limitReset: "daily", name: "Updated API Key Name", }, }); console.log(result); } run(); ``` ### Standalone function The standalone function version of this method: ```typescript theme={null} import { OpenRouterCore } from "@openrouter/sdk/core.js"; import { apiKeysUpdate } from "@openrouter/sdk/funcs/apiKeysUpdate.js"; // Use `OpenRouterCore` for best tree-shaking performance. // You can create one instance of it to use across an application. const openRouter = new OpenRouterCore({ httpReferer: "", appTitle: "", appCategories: "", apiKey: process.env["OPENROUTER_API_KEY"] ?? "", }); async function run() { const res = await apiKeysUpdate(openRouter, { hash: "f01d52606dc8f0a8303a7b5cc3fa07109c2e346cec7c0a16b40de462992ce943", requestBody: { disabled: false, includeByokInLimit: true, limit: 75, limitReset: "daily", name: "Updated API Key Name", }, }); if (res.ok) { const { value: result } = res; console.log(result); } else { console.log("apiKeysUpdate failed:", res.error); } } run(); ``` ### Parameters | Parameter | Type | Required | Description | | ---------------------- | --------------------------------------------------------------------------------------- | -------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | | `request` | [operations.UpdateKeysRequest](../../models/operations/updatekeysrequest.mdx) | :heavy\_check\_mark: | The request object to use for the request. | | `options` | RequestOptions | :heavy\_minus\_sign: | Used to set various options for making HTTP requests. | | `options.fetchOptions` | [RequestInit](https://developer.mozilla.org/en-US/docs/Web/API/Request/Request#options) | :heavy\_minus\_sign: | 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](../../lib/utils/retryconfig.mdx) | :heavy\_minus\_sign: | Enables retrying HTTP requests under certain failure conditions. | ### Response **Promise\<[operations.UpdateKeysResponse](../../models/operations/updatekeysresponse.mdx)>** ### 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 | \*/\* |