Byok - Go SDK

Byok method reference

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

Overview

BYOK endpoints

Available Operations

  • List - List BYOK provider credentials
  • Get - Get a BYOK provider credential

List

List the bring-your-own-key (BYOK) provider credentials for the authenticated entity’s default workspace. Use the workspace_id query parameter to scope the result to a different workspace, or the provider query parameter to filter by upstream provider. 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.Byok.List(ctx, optionalnullable.From[int64](nil), nil, nil, nil)
19 if err != nil {
20 log.Fatal(err)
21 }
22 if res != nil {
23 for {
24 // handle items
25
26 res, err = res.Next()
27
28 if err != nil {
29 // handle error
30 }
31
32 if res == nil {
33 break
34 }
35 }
36 }
37}

Parameters

ParameterTypeRequiredDescriptionExample
ctxcontext.Context✔️The context to use for the request.
offsetoptionalnullable.OptionalNullable[int64]Number of records to skip for pagination0
limit*int64Maximum number of records to return (max 100)50
workspaceID*stringOptional workspace ID to filter by. Defaults to the authenticated entity’s default workspace.550e8400-e29b-41d4-a716-446655440000
provider*operations.ProviderOptional provider slug to filter by (e.g. openai, anthropic, amazon-bedrock).openai
opts[]operations.OptionThe options for this request.

Response

*operations.ListBYOKKeysResponse, error

Errors

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

Get

Get a single bring-your-own-key (BYOK) provider credential by its id. Defaults to the authenticated entity’s default workspace; use the workspace_id query parameter to scope to a different workspace. 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.Byok.Get(ctx, "11111111-2222-3333-4444-555555555555", nil)
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.
idstring✔️The BYOK credential ID (UUID).11111111-2222-3333-4444-555555555555
workspaceID*stringOptional workspace ID. Defaults to the authenticated entity’s default workspace.550e8400-e29b-41d4-a716-446655440000
opts[]operations.OptionThe options for this request.

Response

*components.GetBYOKKeyResponse, error

Errors

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