> ## 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 ```go theme={null} package main import( "context" "os" openrouter "github.com/OpenRouterTeam/go-sdk" "log" ) func main() { ctx := context.Background() s := openrouter.New( openrouter.WithSecurity(os.Getenv("OPENROUTER_API_KEY")), ) res, err := s.APIKeys.GetCurrentKeyMetadata(ctx) if err != nil { log.Fatal(err) } if res != nil { // handle response } } ``` ### Parameters | Parameter | Type | Required | Description | | --------- | ---------------------------------------------------------- | -------------------- | ----------------------------------- | | `ctx` | [context.Context](https://pkg.go.dev/context#Context) | :heavy\_check\_mark: | The context to use for the request. | | `opts` | \[][operations.Option](../../models/operations/option.mdx) | :heavy\_minus\_sign: | The options for this request. | ### Response **[\*operations.GetCurrentKeyResponse](../../models/operations/getcurrentkeyresponse.mdx), error** ### Errors | Error Type | Status Code | Content Type | | ------------------------------------- | ----------- | ---------------- | | sdkerrors.UnauthorizedResponseError | 401 | application/json | | sdkerrors.InternalServerResponseError | 500 | application/json | | sdkerrors.APIError | 4XX, 5XX | \*/\* | ## List List all API keys for the authenticated user. [Management key](/docs/client-sdks/go/docs/guides/overview/auth/management-api-keys) required. ### Example Usage ```go theme={null} package main import( "context" "os" openrouter "github.com/OpenRouterTeam/go-sdk" "github.com/OpenRouterTeam/go-sdk/optionalnullable" "log" ) func main() { ctx := context.Background() s := openrouter.New( openrouter.WithSecurity(os.Getenv("OPENROUTER_API_KEY")), ) res, err := s.APIKeys.List(ctx, nil, optionalnullable.From[int64](nil), nil) if err != nil { log.Fatal(err) } if res != nil { // handle response } } ``` ### Parameters | Parameter | Type | Required | Description | Example | | ----------------- | ---------------------------------------------------------- | -------------------- | ---------------------------------------------------------------------------------------- | ------------------------------------ | | `ctx` | [context.Context](https://pkg.go.dev/context#Context) | :heavy\_check\_mark: | The context to use for the request. | | | `includeDisabled` | `*bool` | :heavy\_minus\_sign: | Whether to include disabled API keys in the response | false | | `offset` | optionalnullable.OptionalNullable\[`int64`] | :heavy\_minus\_sign: | Number of API keys to skip for pagination | 0 | | `workspaceID` | `*string` | :heavy\_minus\_sign: | Filter API keys by workspace ID. By default, keys in the default workspace are returned. | 0df9e665-d932-5740-b2c7-b52af166bc11 | | `opts` | \[][operations.Option](../../models/operations/option.mdx) | :heavy\_minus\_sign: | The options for this request. | | ### Response **[\*operations.ListResponse](../../models/operations/listresponse.mdx), error** ### Errors | Error Type | Status Code | Content Type | | -------------------------------------- | ----------- | ---------------- | | sdkerrors.BadRequestResponseError | 400 | application/json | | sdkerrors.UnauthorizedResponseError | 401 | application/json | | sdkerrors.TooManyRequestsResponseError | 429 | application/json | | sdkerrors.InternalServerResponseError | 500 | application/json | | sdkerrors.APIError | 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/go/docs/guides/overview/auth/management-api-keys). The optional `external` object associates the key with a partner-defined user and lookup key. ### Example Usage ```go theme={null} package main import( "context" "os" openrouter "github.com/OpenRouterTeam/go-sdk" "github.com/OpenRouterTeam/go-sdk/types" "github.com/OpenRouterTeam/go-sdk/optionalnullable" "github.com/OpenRouterTeam/go-sdk/models/operations" "log" ) func main() { ctx := context.Background() s := openrouter.New( openrouter.WithSecurity(os.Getenv("OPENROUTER_API_KEY")), ) res, err := s.APIKeys.Create(ctx, operations.CreateKeysRequest{ ExpiresAt: optionalnullable.From(openrouter.Pointer(types.MustNewTimeFromString("2027-12-31T23:59:59Z"))), IncludeBYOKInLimit: openrouter.Pointer(true), Limit: optionalnullable.From(openrouter.Pointer[float64](50.0)), LimitReset: optionalnullable.From(openrouter.Pointer(operations.CreateKeysLimitResetMonthly)), Name: "My New API Key", }) if err != nil { log.Fatal(err) } if res != nil { // handle response } } ``` ### Parameters | Parameter | Type | Required | Description | | --------- | ----------------------------------------------------------------------------- | -------------------- | ------------------------------------------ | | `ctx` | [context.Context](https://pkg.go.dev/context#Context) | :heavy\_check\_mark: | The context to use for the request. | | `request` | [operations.CreateKeysRequest](../../models/operations/createkeysrequest.mdx) | :heavy\_check\_mark: | The request object to use for the request. | | `opts` | \[][operations.Option](../../models/operations/option.mdx) | :heavy\_minus\_sign: | The options for this request. | ### Response **[\*operations.CreateKeysResponse](../../models/operations/createkeysresponse.mdx), error** ### Errors | Error Type | Status Code | Content Type | | -------------------------------------- | ----------- | ---------------- | | sdkerrors.BadRequestResponseError | 400 | application/json | | sdkerrors.UnauthorizedResponseError | 401 | application/json | | sdkerrors.ForbiddenResponseError | 403 | application/json | | sdkerrors.TooManyRequestsResponseError | 429 | application/json | | sdkerrors.InternalServerResponseError | 500 | application/json | | sdkerrors.APIError | 4XX, 5XX | \*/\* | ## Delete Delete an existing API key. Authenticate with a [management key](/docs/client-sdks/go/docs/guides/overview/auth/management-api-keys). ### Example Usage ```go theme={null} package main import( "context" "os" openrouter "github.com/OpenRouterTeam/go-sdk" "log" ) func main() { ctx := context.Background() s := openrouter.New( openrouter.WithSecurity(os.Getenv("OPENROUTER_API_KEY")), ) res, err := s.APIKeys.Delete(ctx, "f01d52606dc8f0a8303a7b5cc3fa07109c2e346cec7c0a16b40de462992ce943") if err != nil { log.Fatal(err) } if res != nil { // handle response } } ``` ### Parameters | Parameter | Type | Required | Description | Example | | --------- | ---------------------------------------------------------- | -------------------- | -------------------------------------------- | ---------------------------------------------------------------- | | `ctx` | [context.Context](https://pkg.go.dev/context#Context) | :heavy\_check\_mark: | The context to use for the request. | | | `hash` | `string` | :heavy\_check\_mark: | The hash identifier of the API key to delete | f01d52606dc8f0a8303a7b5cc3fa07109c2e346cec7c0a16b40de462992ce943 | | `opts` | \[][operations.Option](../../models/operations/option.mdx) | :heavy\_minus\_sign: | The options for this request. | | ### Response **[\*operations.DeleteKeysResponse](../../models/operations/deletekeysresponse.mdx), error** ### Errors | Error Type | Status Code | Content Type | | -------------------------------------- | ----------- | ---------------- | | sdkerrors.UnauthorizedResponseError | 401 | application/json | | sdkerrors.NotFoundResponseError | 404 | application/json | | sdkerrors.TooManyRequestsResponseError | 429 | application/json | | sdkerrors.InternalServerResponseError | 500 | application/json | | sdkerrors.APIError | 4XX, 5XX | \*/\* | ## Get Get a single API key by hash. [Management key](/docs/client-sdks/go/docs/guides/overview/auth/management-api-keys) required. ### Example Usage ```go theme={null} package main import( "context" "os" openrouter "github.com/OpenRouterTeam/go-sdk" "log" ) func main() { ctx := context.Background() s := openrouter.New( openrouter.WithSecurity(os.Getenv("OPENROUTER_API_KEY")), ) res, err := s.APIKeys.Get(ctx, "f01d52606dc8f0a8303a7b5cc3fa07109c2e346cec7c0a16b40de462992ce943") if err != nil { log.Fatal(err) } if res != nil { // handle response } } ``` ### Parameters | Parameter | Type | Required | Description | Example | | --------- | ---------------------------------------------------------- | -------------------- | ---------------------------------------------- | ---------------------------------------------------------------- | | `ctx` | [context.Context](https://pkg.go.dev/context#Context) | :heavy\_check\_mark: | The context to use for the request. | | | `hash` | `string` | :heavy\_check\_mark: | The hash identifier of the API key to retrieve | f01d52606dc8f0a8303a7b5cc3fa07109c2e346cec7c0a16b40de462992ce943 | | `opts` | \[][operations.Option](../../models/operations/option.mdx) | :heavy\_minus\_sign: | The options for this request. | | ### Response **[\*operations.GetKeyResponse](../../models/operations/getkeyresponse.mdx), error** ### Errors | Error Type | Status Code | Content Type | | -------------------------------------- | ----------- | ---------------- | | sdkerrors.UnauthorizedResponseError | 401 | application/json | | sdkerrors.NotFoundResponseError | 404 | application/json | | sdkerrors.TooManyRequestsResponseError | 429 | application/json | | sdkerrors.InternalServerResponseError | 500 | application/json | | sdkerrors.APIError | 4XX, 5XX | \*/\* | ## Update Update an existing API key. Authenticate with a [management key](/docs/client-sdks/go/docs/guides/overview/auth/management-api-keys). ### Example Usage ```go theme={null} package main import( "context" "os" openrouter "github.com/OpenRouterTeam/go-sdk" "github.com/OpenRouterTeam/go-sdk/optionalnullable" "github.com/OpenRouterTeam/go-sdk/models/operations" "log" ) func main() { ctx := context.Background() s := openrouter.New( openrouter.WithSecurity(os.Getenv("OPENROUTER_API_KEY")), ) res, err := s.APIKeys.Update(ctx, "f01d52606dc8f0a8303a7b5cc3fa07109c2e346cec7c0a16b40de462992ce943", operations.UpdateKeysRequestBody{ Disabled: openrouter.Pointer(false), IncludeBYOKInLimit: openrouter.Pointer(true), Limit: optionalnullable.From(openrouter.Pointer[float64](75.0)), LimitReset: optionalnullable.From(openrouter.Pointer(operations.UpdateKeysLimitResetDaily)), Name: openrouter.Pointer("Updated API Key Name"), }) if err != nil { log.Fatal(err) } if res != nil { // handle response } } ``` ### Parameters | Parameter | Type | Required | Description | Example | | ------------- | ------------------------------------------------------------------------------------- | -------------------- | -------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------ | | `ctx` | [context.Context](https://pkg.go.dev/context#Context) | :heavy\_check\_mark: | The context to use for the request. | | | `hash` | `string` | :heavy\_check\_mark: | The hash identifier of the API key to update | f01d52606dc8f0a8303a7b5cc3fa07109c2e346cec7c0a16b40de462992ce943 | | `requestBody` | [operations.UpdateKeysRequestBody](../../models/operations/updatekeysrequestbody.mdx) | :heavy\_check\_mark: | N/A | \{
"disabled": false,
"include\_byok\_in\_limit": true,
"limit": 75,
"limit\_reset": "daily",
"name": "Updated API Key Name"
} | | `opts` | \[][operations.Option](../../models/operations/option.mdx) | :heavy\_minus\_sign: | The options for this request. | | ### Response **[\*operations.UpdateKeysResponse](../../models/operations/updatekeysresponse.mdx), error** ### Errors | Error Type | Status Code | Content Type | | -------------------------------------- | ----------- | ---------------- | | sdkerrors.BadRequestResponseError | 400 | application/json | | sdkerrors.UnauthorizedResponseError | 401 | application/json | | sdkerrors.NotFoundResponseError | 404 | application/json | | sdkerrors.TooManyRequestsResponseError | 429 | application/json | | sdkerrors.InternalServerResponseError | 500 | application/json | | sdkerrors.APIError | 4XX, 5XX | \*/\* |