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
  • 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
  • ListGuardrailKeyAssignments
  • Example Usage
  • Parameters
  • Response
  • Errors
  • BulkAssignKeys
  • Example Usage
  • Parameters
  • Response
  • Errors
  • BulkUnassignKeys
  • Example Usage
  • Parameters
  • Response
  • Errors
  • ListGuardrailMemberAssignments
  • Example Usage
  • Parameters
  • Response
  • Errors
  • BulkAssignMembers
  • Example Usage
  • Parameters
  • Response
  • Errors
  • BulkUnassignMembers
  • Example Usage
  • Parameters
  • Response
  • Errors
  • ListKeyAssignments
  • Example Usage
  • Parameters
  • Response
  • Errors
  • ListMemberAssignments
  • Example Usage
  • Parameters
  • Response
  • Errors
Go SDKAPI Reference

Guardrails - Go SDK

Guardrails method reference
Was this page helpful?
Previous

Models - Go SDK

Models method reference
Next
Built with

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

Overview

Guardrails endpoints

Available Operations

  • List - List guardrails
  • Create - Create a guardrail
  • Delete - Delete a guardrail
  • Get - Get a guardrail
  • Update - Update a guardrail
  • ListGuardrailKeyAssignments - List key assignments for a guardrail
  • BulkAssignKeys - Bulk assign keys to a guardrail
  • BulkUnassignKeys - Bulk unassign keys from a guardrail
  • ListGuardrailMemberAssignments - List member assignments for a guardrail
  • BulkAssignMembers - Bulk assign members to a guardrail
  • BulkUnassignMembers - Bulk unassign members from a guardrail
  • ListKeyAssignments - List all key assignments
  • ListMemberAssignments - List all member assignments

List

List all guardrails 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.Guardrails.List(ctx, optionalnullable.From[int64](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*int64➖Maximum number of records to return (max 100)50
workspaceID*string➖Filter guardrails by workspace ID. By default, guardrails in the default workspace are returned.0df9e665-d932-5740-b2c7-b52af166bc11
opts[]operations.Option➖The options for this request.

Response

*operations.ListGuardrailsResponse, error

Errors

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

Create

Create a new guardrail 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 "github.com/OpenRouterTeam/go-sdk/models/components"
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.Guardrails.Create(ctx, components.CreateGuardrailRequest{
20 AllowedModels: optionalnullable.From[[]string](nil),
21 AllowedProviders: optionalnullable.From(openrouter.Pointer([]string{
22 "openai",
23 "anthropic",
24 "deepseek",
25 })),
26 Description: optionalnullable.From(openrouter.Pointer("A guardrail for limiting API usage")),
27 EnforceZdrAnthropic: optionalnullable.From(openrouter.Pointer(true)),
28 EnforceZdrGoogle: optionalnullable.From(openrouter.Pointer(false)),
29 EnforceZdrOpenai: optionalnullable.From(openrouter.Pointer(true)),
30 EnforceZdrOther: optionalnullable.From(openrouter.Pointer(false)),
31 IgnoredModels: optionalnullable.From[[]string](nil),
32 IgnoredProviders: optionalnullable.From[[]string](nil),
33 LimitUsd: optionalnullable.From(openrouter.Pointer[float64](50.0)),
34 Name: "My New Guardrail",
35 ResetInterval: optionalnullable.From(openrouter.Pointer(components.GuardrailIntervalMonthly)),
36 })
37 if err != nil {
38 log.Fatal(err)
39 }
40 if res != nil {
41 // handle response
42 }
43}

Parameters

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

Response

*components.CreateGuardrailResponse, error

Errors

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

Delete

Delete an existing guardrail. 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.Guardrails.Delete(ctx, "550e8400-e29b-41d4-a716-446655440000")
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 unique identifier of the guardrail to delete550e8400-e29b-41d4-a716-446655440000
opts[]operations.Option➖The options for this request.

Response

*components.DeleteGuardrailResponse, error

Errors

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

Get

Get a single guardrail by ID. 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.Guardrails.Get(ctx, "550e8400-e29b-41d4-a716-446655440000")
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 unique identifier of the guardrail to retrieve550e8400-e29b-41d4-a716-446655440000
opts[]operations.Option➖The options for this request.

Response

*components.GetGuardrailResponse, error

Errors

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

Update

Update an existing guardrail. 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/components"
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.Guardrails.Update(ctx, "550e8400-e29b-41d4-a716-446655440000", components.UpdateGuardrailRequest{
20 Description: optionalnullable.From(openrouter.Pointer("Updated description")),
21 LimitUsd: optionalnullable.From(openrouter.Pointer[float64](75.0)),
22 Name: openrouter.Pointer("Updated Guardrail Name"),
23 ResetInterval: optionalnullable.From(openrouter.Pointer(components.GuardrailIntervalWeekly)),
24 })
25 if err != nil {
26 log.Fatal(err)
27 }
28 if res != nil {
29 // handle response
30 }
31}

Parameters

ParameterTypeRequiredDescriptionExample
ctxcontext.Context✔️The context to use for the request.
idstring✔️The unique identifier of the guardrail to update550e8400-e29b-41d4-a716-446655440000
updateGuardrailRequestcomponents.UpdateGuardrailRequest✔️N/A{"description": "Updated description","limit_usd": 75,"name": "Updated Guardrail Name","reset_interval": "weekly"}
opts[]operations.Option➖The options for this request.

Response

*components.UpdateGuardrailResponse, error

Errors

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

ListGuardrailKeyAssignments

List all API key assignments for a specific guardrail. 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.Guardrails.ListGuardrailKeyAssignments(ctx, "550e8400-e29b-41d4-a716-446655440000", optionalnullable.From[int64](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.
idstring✔️The unique identifier of the guardrail550e8400-e29b-41d4-a716-446655440000
offsetoptionalnullable.OptionalNullable[int64]➖Number of records to skip for pagination0
limit*int64➖Maximum number of records to return (max 100)50
opts[]operations.Option➖The options for this request.

Response

*operations.ListGuardrailKeyAssignmentsResponse, error

Errors

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

BulkAssignKeys

Assign multiple API keys to a specific guardrail. 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/models/components"
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.Guardrails.BulkAssignKeys(ctx, "550e8400-e29b-41d4-a716-446655440000", components.BulkAssignKeysRequest{
19 KeyHashes: []string{
20 "c56454edb818d6b14bc0d61c46025f1450b0f4012d12304ab40aacb519fcbc93",
21 },
22 })
23 if err != nil {
24 log.Fatal(err)
25 }
26 if res != nil {
27 // handle response
28 }
29}

Parameters

ParameterTypeRequiredDescriptionExample
ctxcontext.Context✔️The context to use for the request.
idstring✔️The unique identifier of the guardrail550e8400-e29b-41d4-a716-446655440000
bulkAssignKeysRequestcomponents.BulkAssignKeysRequest✔️N/A{"key_hashes": ["c56454edb818d6b14bc0d61c46025f1450b0f4012d12304ab40aacb519fcbc93"]}
opts[]operations.Option➖The options for this request.

Response

*components.BulkAssignKeysResponse, error

Errors

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

BulkUnassignKeys

Unassign multiple API keys from a specific guardrail. 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/models/components"
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.Guardrails.BulkUnassignKeys(ctx, "550e8400-e29b-41d4-a716-446655440000", components.BulkUnassignKeysRequest{
19 KeyHashes: []string{
20 "c56454edb818d6b14bc0d61c46025f1450b0f4012d12304ab40aacb519fcbc93",
21 },
22 })
23 if err != nil {
24 log.Fatal(err)
25 }
26 if res != nil {
27 // handle response
28 }
29}

Parameters

ParameterTypeRequiredDescriptionExample
ctxcontext.Context✔️The context to use for the request.
idstring✔️The unique identifier of the guardrail550e8400-e29b-41d4-a716-446655440000
bulkUnassignKeysRequestcomponents.BulkUnassignKeysRequest✔️N/A{"key_hashes": ["c56454edb818d6b14bc0d61c46025f1450b0f4012d12304ab40aacb519fcbc93"]}
opts[]operations.Option➖The options for this request.

Response

*components.BulkUnassignKeysResponse, error

Errors

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

ListGuardrailMemberAssignments

List all organization member assignments for a specific guardrail. 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.Guardrails.ListGuardrailMemberAssignments(ctx, "550e8400-e29b-41d4-a716-446655440000", optionalnullable.From[int64](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.
idstring✔️The unique identifier of the guardrail550e8400-e29b-41d4-a716-446655440000
offsetoptionalnullable.OptionalNullable[int64]➖Number of records to skip for pagination0
limit*int64➖Maximum number of records to return (max 100)50
opts[]operations.Option➖The options for this request.

Response

*operations.ListGuardrailMemberAssignmentsResponse, error

Errors

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

BulkAssignMembers

Assign multiple organization members to a specific guardrail. 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/models/components"
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.Guardrails.BulkAssignMembers(ctx, "550e8400-e29b-41d4-a716-446655440000", components.BulkAssignMembersRequest{
19 MemberUserIds: []string{
20 "user_abc123",
21 "user_def456",
22 },
23 })
24 if err != nil {
25 log.Fatal(err)
26 }
27 if res != nil {
28 // handle response
29 }
30}

Parameters

ParameterTypeRequiredDescriptionExample
ctxcontext.Context✔️The context to use for the request.
idstring✔️The unique identifier of the guardrail550e8400-e29b-41d4-a716-446655440000
bulkAssignMembersRequestcomponents.BulkAssignMembersRequest✔️N/A{"member_user_ids": ["user_abc123","user_def456"]}
opts[]operations.Option➖The options for this request.

Response

*components.BulkAssignMembersResponse, error

Errors

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

BulkUnassignMembers

Unassign multiple organization members from a specific guardrail. 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/models/components"
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.Guardrails.BulkUnassignMembers(ctx, "550e8400-e29b-41d4-a716-446655440000", components.BulkUnassignMembersRequest{
19 MemberUserIds: []string{
20 "user_abc123",
21 "user_def456",
22 },
23 })
24 if err != nil {
25 log.Fatal(err)
26 }
27 if res != nil {
28 // handle response
29 }
30}

Parameters

ParameterTypeRequiredDescriptionExample
ctxcontext.Context✔️The context to use for the request.
idstring✔️The unique identifier of the guardrail550e8400-e29b-41d4-a716-446655440000
bulkUnassignMembersRequestcomponents.BulkUnassignMembersRequest✔️N/A{"member_user_ids": ["user_abc123","user_def456"]}
opts[]operations.Option➖The options for this request.

Response

*components.BulkUnassignMembersResponse, error

Errors

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

ListKeyAssignments

List all API key guardrail assignments 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.Guardrails.ListKeyAssignments(ctx, optionalnullable.From[int64](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*int64➖Maximum number of records to return (max 100)50
opts[]operations.Option➖The options for this request.

Response

*operations.ListKeyAssignmentsResponse, error

Errors

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

ListMemberAssignments

List all organization member guardrail assignments 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.Guardrails.ListMemberAssignments(ctx, optionalnullable.From[int64](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*int64➖Maximum number of records to return (max 100)50
opts[]operations.Option➖The options for this request.

Response

*operations.ListMemberAssignmentsResponse, error

Errors

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