For AI agents: a documentation index is available at the root level at /llms.txt and /llms-full.txt. Append /llms.txt to any URL for a page-level index, or .md for the markdown version of any page.
ModelsChatRankingsDocs
DocsAPI ReferenceClient SDKsAgent SDKCookbookChangelog
DocsAPI ReferenceClient SDKsAgent SDKCookbookChangelog
    • Overview
    • Usage for Agents
  • TypeScript SDK
    • Overview
  • Python SDK
    • Overview
  • Go SDK
      • Analytics
      • APIKeys
      • Byok
      • Chat
      • Credits
      • Embeddings
      • Endpoints
      • Generations
      • Guardrails
      • OAuth
      • Observability
      • Organization
      • Presets
      • Providers
      • Rerank
      • Beta.Responses
      • Transcriptions
      • Speech
      • VideoGeneration
      • Workspaces
  • DevTools
    • Overview
    • Migrating to @openrouter/agent
LogoLogo
ModelsChatRankingsDocs
On this page
  • Overview
  • Available Operations
  • GetCurrentKeyMetadata
  • Example Usage
  • Parameters
  • Response
  • Errors
  • List
  • Example Usage
  • Parameters
  • Response
  • Errors
  • Create
  • Example Usage
  • Parameters
  • Response
  • Errors
  • Delete
  • Example Usage
  • Parameters
  • Response
  • Errors
  • Get
  • Example Usage
  • Parameters
  • Response
  • Errors
  • Update
  • Example Usage
  • Parameters
  • Response
  • Errors
Go SDKAPI Reference

APIKeys - Go SDK

APIKeys method reference
Was this page helpful?
Previous

Byok - Go SDK

Byok method reference
Next
Built with

The Go SDK and docs are currently in beta. Report issues on GitHub.

Overview

API key management endpoints

Available Operations

  • GetCurrentKeyMetadata - Get current API key
  • List - List API keys
  • Create - Create a new API key
  • Delete - Delete an API key
  • Get - Get a single API key
  • Update - Update an API key

GetCurrentKeyMetadata

Get information on the API key associated with the current authentication session

Example Usage

1package main
2
3import(
4 "context"
5 "os"
6 openrouter "github.com/OpenRouterTeam/go-sdk"
7 "log"
8)
9
10func main() {
11 ctx := context.Background()
12
13 s := openrouter.New(
14 openrouter.WithSecurity(os.Getenv("OPENROUTER_API_KEY")),
15 )
16
17 res, err := s.APIKeys.GetCurrentKeyMetadata(ctx)
18 if err != nil {
19 log.Fatal(err)
20 }
21 if res != nil {
22 // handle response
23 }
24}

Parameters

ParameterTypeRequiredDescription
ctxcontext.Context✔️The context to use for the request.
opts[]operations.Option➖The options for this request.

Response

*operations.GetCurrentKeyResponse, error

Errors

Error TypeStatus CodeContent Type
sdkerrors.UnauthorizedResponseError401application/json
sdkerrors.InternalServerResponseError500application/json
sdkerrors.APIError4XX, 5XX*/*

List

List all API keys for the authenticated user. Management key required.

Example Usage

1package main
2
3import(
4 "context"
5 "os"
6 openrouter "github.com/OpenRouterTeam/go-sdk"
7 "github.com/OpenRouterTeam/go-sdk/optionalnullable"
8 "log"
9)
10
11func main() {
12 ctx := context.Background()
13
14 s := openrouter.New(
15 openrouter.WithSecurity(os.Getenv("OPENROUTER_API_KEY")),
16 )
17
18 res, err := s.APIKeys.List(ctx, nil, optionalnullable.From[int64](nil), nil)
19 if err != nil {
20 log.Fatal(err)
21 }
22 if res != nil {
23 // handle response
24 }
25}

Parameters

ParameterTypeRequiredDescriptionExample
ctxcontext.Context✔️The context to use for the request.
includeDisabled*bool➖Whether to include disabled API keys in the responsefalse
offsetoptionalnullable.OptionalNullable[int64]➖Number of API keys to skip for pagination0
workspaceID*string➖Filter API keys by workspace ID. By default, keys in the default workspace are returned.0df9e665-d932-5740-b2c7-b52af166bc11
opts[]operations.Option➖The options for this request.

Response

*operations.ListResponse, error

Errors

Error TypeStatus CodeContent Type
sdkerrors.UnauthorizedResponseError401application/json
sdkerrors.TooManyRequestsResponseError429application/json
sdkerrors.InternalServerResponseError500application/json
sdkerrors.APIError4XX, 5XX*/*

Create

Create a new API key for the authenticated user. Management key required.

Example Usage

1package main
2
3import(
4 "context"
5 "os"
6 openrouter "github.com/OpenRouterTeam/go-sdk"
7 "github.com/OpenRouterTeam/go-sdk/types"
8 "github.com/OpenRouterTeam/go-sdk/optionalnullable"
9 "github.com/OpenRouterTeam/go-sdk/models/operations"
10 "log"
11)
12
13func main() {
14 ctx := context.Background()
15
16 s := openrouter.New(
17 openrouter.WithSecurity(os.Getenv("OPENROUTER_API_KEY")),
18 )
19
20 res, err := s.APIKeys.Create(ctx, operations.CreateKeysRequest{
21 ExpiresAt: optionalnullable.From(openrouter.Pointer(types.MustNewTimeFromString("2027-12-31T23:59:59Z"))),
22 IncludeByokInLimit: openrouter.Pointer(true),
23 Limit: optionalnullable.From(openrouter.Pointer[float64](50.0)),
24 LimitReset: optionalnullable.From(openrouter.Pointer(operations.CreateKeysLimitResetMonthly)),
25 Name: "My New API Key",
26 })
27 if err != nil {
28 log.Fatal(err)
29 }
30 if res != nil {
31 // handle response
32 }
33}

Parameters

ParameterTypeRequiredDescription
ctxcontext.Context✔️The context to use for the request.
requestoperations.CreateKeysRequest✔️The request object to use for the request.
opts[]operations.Option➖The options for this request.

Response

*operations.CreateKeysResponse, error

Errors

Error TypeStatus CodeContent Type
sdkerrors.BadRequestResponseError400application/json
sdkerrors.UnauthorizedResponseError401application/json
sdkerrors.ForbiddenResponseError403application/json
sdkerrors.TooManyRequestsResponseError429application/json
sdkerrors.InternalServerResponseError500application/json
sdkerrors.APIError4XX, 5XX*/*

Delete

Delete an existing API key. Management key required.

Example Usage

1package main
2
3import(
4 "context"
5 "os"
6 openrouter "github.com/OpenRouterTeam/go-sdk"
7 "log"
8)
9
10func main() {
11 ctx := context.Background()
12
13 s := openrouter.New(
14 openrouter.WithSecurity(os.Getenv("OPENROUTER_API_KEY")),
15 )
16
17 res, err := s.APIKeys.Delete(ctx, "f01d52606dc8f0a8303a7b5cc3fa07109c2e346cec7c0a16b40de462992ce943")
18 if err != nil {
19 log.Fatal(err)
20 }
21 if res != nil {
22 // handle response
23 }
24}

Parameters

ParameterTypeRequiredDescriptionExample
ctxcontext.Context✔️The context to use for the request.
hashstring✔️The hash identifier of the API key to deletef01d52606dc8f0a8303a7b5cc3fa07109c2e346cec7c0a16b40de462992ce943
opts[]operations.Option➖The options for this request.

Response

*operations.DeleteKeysResponse, error

Errors

Error TypeStatus CodeContent Type
sdkerrors.UnauthorizedResponseError401application/json
sdkerrors.NotFoundResponseError404application/json
sdkerrors.TooManyRequestsResponseError429application/json
sdkerrors.InternalServerResponseError500application/json
sdkerrors.APIError4XX, 5XX*/*

Get

Get a single API key by hash. Management key required.

Example Usage

1package main
2
3import(
4 "context"
5 "os"
6 openrouter "github.com/OpenRouterTeam/go-sdk"
7 "log"
8)
9
10func main() {
11 ctx := context.Background()
12
13 s := openrouter.New(
14 openrouter.WithSecurity(os.Getenv("OPENROUTER_API_KEY")),
15 )
16
17 res, err := s.APIKeys.Get(ctx, "f01d52606dc8f0a8303a7b5cc3fa07109c2e346cec7c0a16b40de462992ce943")
18 if err != nil {
19 log.Fatal(err)
20 }
21 if res != nil {
22 // handle response
23 }
24}

Parameters

ParameterTypeRequiredDescriptionExample
ctxcontext.Context✔️The context to use for the request.
hashstring✔️The hash identifier of the API key to retrievef01d52606dc8f0a8303a7b5cc3fa07109c2e346cec7c0a16b40de462992ce943
opts[]operations.Option➖The options for this request.

Response

*operations.GetKeyResponse, error

Errors

Error TypeStatus CodeContent Type
sdkerrors.UnauthorizedResponseError401application/json
sdkerrors.NotFoundResponseError404application/json
sdkerrors.TooManyRequestsResponseError429application/json
sdkerrors.InternalServerResponseError500application/json
sdkerrors.APIError4XX, 5XX*/*

Update

Update an existing API key. Management key required.

Example Usage

1package main
2
3import(
4 "context"
5 "os"
6 openrouter "github.com/OpenRouterTeam/go-sdk"
7 "github.com/OpenRouterTeam/go-sdk/optionalnullable"
8 "github.com/OpenRouterTeam/go-sdk/models/operations"
9 "log"
10)
11
12func main() {
13 ctx := context.Background()
14
15 s := openrouter.New(
16 openrouter.WithSecurity(os.Getenv("OPENROUTER_API_KEY")),
17 )
18
19 res, err := s.APIKeys.Update(ctx, "f01d52606dc8f0a8303a7b5cc3fa07109c2e346cec7c0a16b40de462992ce943", operations.UpdateKeysRequestBody{
20 Disabled: openrouter.Pointer(false),
21 IncludeByokInLimit: openrouter.Pointer(true),
22 Limit: optionalnullable.From(openrouter.Pointer[float64](75.0)),
23 LimitReset: optionalnullable.From(openrouter.Pointer(operations.UpdateKeysLimitResetDaily)),
24 Name: openrouter.Pointer("Updated API Key Name"),
25 })
26 if err != nil {
27 log.Fatal(err)
28 }
29 if res != nil {
30 // handle response
31 }
32}

Parameters

ParameterTypeRequiredDescriptionExample
ctxcontext.Context✔️The context to use for the request.
hashstring✔️The hash identifier of the API key to updatef01d52606dc8f0a8303a7b5cc3fa07109c2e346cec7c0a16b40de462992ce943
requestBodyoperations.UpdateKeysRequestBody✔️N/A{"disabled": false,"include_byok_in_limit": true,"limit": 75,"limit_reset": "daily","name": "Updated API Key Name"}
opts[]operations.Option➖The options for this request.

Response

*operations.UpdateKeysResponse, error

Errors

Error TypeStatus CodeContent Type
sdkerrors.BadRequestResponseError400application/json
sdkerrors.UnauthorizedResponseError401application/json
sdkerrors.NotFoundResponseError404application/json
sdkerrors.TooManyRequestsResponseError429application/json
sdkerrors.InternalServerResponseError500application/json
sdkerrors.APIError4XX, 5XX*/*