For AI client integration (Claude Code, Cursor, etc.), connect to the MCP server at https://modelgates.ai/docs/_mcp/server.

Guardrails - Go SDK

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

Overview

Guardrails endpoints

Available Operations

List

List all guardrails for the authenticated user. Management key required.

Example Usage

go
package main import(	"context"	"os"	modelgates "github.com/ModelGatesTeam/go-sdk"	"github.com/ModelGatesTeam/go-sdk/optionalnullable"	"log") func main() {    ctx := context.Background()     s := modelgates.New(        modelgates.WithSecurity(os.Getenv("MODELGATES_API_KEY")),    )     res, err := s.Guardrails.List(ctx, optionalnullable.From[int64](nil), nil, nil)    if err != nil {        log.Fatal(err)    }    if res != nil {        for {            // handle items             res, err = res.Next()             if err != nil {                // handle error            }             if res == nil {                break            }        }    }}

Parameters

ParameterTypeRequiredDescriptionExample
ctxcontext.Context:heavy_check_mark:The context to use for the request.
offsetoptionalnullable.OptionalNullable[int64]:heavy_minus_sign:Number of records to skip for pagination0
limit*int64:heavy_minus_sign:Maximum number of records to return (max 100)50
workspaceID*string:heavy_minus_sign:Filter guardrails by workspace ID. By default, guardrails in the default workspace are returned.0df9e665-d932-5740-b2c7-b52af166bc11
opts[]operations.Option:heavy_minus_sign: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

go
package main import(	"context"	"os"	modelgates "github.com/ModelGatesTeam/go-sdk"	"github.com/ModelGatesTeam/go-sdk/optionalnullable"	"github.com/ModelGatesTeam/go-sdk/models/components"	"log") func main() {    ctx := context.Background()     s := modelgates.New(        modelgates.WithSecurity(os.Getenv("MODELGATES_API_KEY")),    )     res, err := s.Guardrails.Create(ctx, components.CreateGuardrailRequest{        AllowedModels: optionalnullable.From[[]string](nil),        AllowedProviders: optionalnullable.From(modelgates.Pointer([]string{            "openai",            "anthropic",            "deepseek",        })),        Description: optionalnullable.From(modelgates.Pointer("A guardrail for limiting API usage")),        EnforceZdrAnthropic: optionalnullable.From(modelgates.Pointer(true)),        EnforceZdrGoogle: optionalnullable.From(modelgates.Pointer(false)),        EnforceZdrOpenai: optionalnullable.From(modelgates.Pointer(true)),        EnforceZdrOther: optionalnullable.From(modelgates.Pointer(false)),        IgnoredModels: optionalnullable.From[[]string](nil),        IgnoredProviders: optionalnullable.From[[]string](nil),        LimitUsd: optionalnullable.From(modelgates.Pointer[float64](50.0)),        Name: "My New Guardrail",        ResetInterval: optionalnullable.From(modelgates.Pointer(components.GuardrailIntervalMonthly)),    })    if err != nil {        log.Fatal(err)    }    if res != nil {        // handle response    }}

Parameters

ParameterTypeRequiredDescription
ctxcontext.Context:heavy_check_mark:The context to use for the request.
requestcomponents.CreateGuardrailRequest:heavy_check_mark:The request object to use for the request.
opts[]operations.Option:heavy_minus_sign: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

go
package main import(	"context"	"os"	modelgates "github.com/ModelGatesTeam/go-sdk"	"log") func main() {    ctx := context.Background()     s := modelgates.New(        modelgates.WithSecurity(os.Getenv("MODELGATES_API_KEY")),    )     res, err := s.Guardrails.Delete(ctx, "550e8400-e29b-41d4-a716-446655440000")    if err != nil {        log.Fatal(err)    }    if res != nil {        // handle response    }}

Parameters

ParameterTypeRequiredDescriptionExample
ctxcontext.Context:heavy_check_mark:The context to use for the request.
idstring:heavy_check_mark:The unique identifier of the guardrail to delete550e8400-e29b-41d4-a716-446655440000
opts[]operations.Option:heavy_minus_sign: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

go
package main import(	"context"	"os"	modelgates "github.com/ModelGatesTeam/go-sdk"	"log") func main() {    ctx := context.Background()     s := modelgates.New(        modelgates.WithSecurity(os.Getenv("MODELGATES_API_KEY")),    )     res, err := s.Guardrails.Get(ctx, "550e8400-e29b-41d4-a716-446655440000")    if err != nil {        log.Fatal(err)    }    if res != nil {        // handle response    }}

Parameters

ParameterTypeRequiredDescriptionExample
ctxcontext.Context:heavy_check_mark:The context to use for the request.
idstring:heavy_check_mark:The unique identifier of the guardrail to retrieve550e8400-e29b-41d4-a716-446655440000
opts[]operations.Option:heavy_minus_sign: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

go
package main import(	"context"	"os"	modelgates "github.com/ModelGatesTeam/go-sdk"	"github.com/ModelGatesTeam/go-sdk/optionalnullable"	"github.com/ModelGatesTeam/go-sdk/models/components"	"log") func main() {    ctx := context.Background()     s := modelgates.New(        modelgates.WithSecurity(os.Getenv("MODELGATES_API_KEY")),    )     res, err := s.Guardrails.Update(ctx, "550e8400-e29b-41d4-a716-446655440000", components.UpdateGuardrailRequest{        Description: optionalnullable.From(modelgates.Pointer("Updated description")),        LimitUsd: optionalnullable.From(modelgates.Pointer[float64](75.0)),        Name: modelgates.Pointer("Updated Guardrail Name"),        ResetInterval: optionalnullable.From(modelgates.Pointer(components.GuardrailIntervalWeekly)),    })    if err != nil {        log.Fatal(err)    }    if res != nil {        // handle response    }}

Parameters

ParameterTypeRequiredDescriptionExample
ctxcontext.Context:heavy_check_mark:The context to use for the request.
idstring:heavy_check_mark:The unique identifier of the guardrail to update550e8400-e29b-41d4-a716-446655440000
updateGuardrailRequestcomponents.UpdateGuardrailRequest:heavy_check_mark:N/A{"description": "Updated description","limit_usd": 75,"name": "Updated Guardrail Name","reset_interval": "weekly"}
opts[]operations.Option:heavy_minus_sign: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

go
package main import(	"context"	"os"	modelgates "github.com/ModelGatesTeam/go-sdk"	"github.com/ModelGatesTeam/go-sdk/optionalnullable"	"log") func main() {    ctx := context.Background()     s := modelgates.New(        modelgates.WithSecurity(os.Getenv("MODELGATES_API_KEY")),    )     res, err := s.Guardrails.ListGuardrailKeyAssignments(ctx, "550e8400-e29b-41d4-a716-446655440000", optionalnullable.From[int64](nil), nil)    if err != nil {        log.Fatal(err)    }    if res != nil {        for {            // handle items             res, err = res.Next()             if err != nil {                // handle error            }             if res == nil {                break            }        }    }}

Parameters

ParameterTypeRequiredDescriptionExample
ctxcontext.Context:heavy_check_mark:The context to use for the request.
idstring:heavy_check_mark:The unique identifier of the guardrail550e8400-e29b-41d4-a716-446655440000
offsetoptionalnullable.OptionalNullable[int64]:heavy_minus_sign:Number of records to skip for pagination0
limit*int64:heavy_minus_sign:Maximum number of records to return (max 100)50
opts[]operations.Option:heavy_minus_sign: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

go
package main import(	"context"	"os"	modelgates "github.com/ModelGatesTeam/go-sdk"	"github.com/ModelGatesTeam/go-sdk/models/components"	"log") func main() {    ctx := context.Background()     s := modelgates.New(        modelgates.WithSecurity(os.Getenv("MODELGATES_API_KEY")),    )     res, err := s.Guardrails.BulkAssignKeys(ctx, "550e8400-e29b-41d4-a716-446655440000", components.BulkAssignKeysRequest{        KeyHashes: []string{            "c56454edb818d6b14bc0d61c46025f1450b0f4012d12304ab40aacb519fcbc93",        },    })    if err != nil {        log.Fatal(err)    }    if res != nil {        // handle response    }}

Parameters

ParameterTypeRequiredDescriptionExample
ctxcontext.Context:heavy_check_mark:The context to use for the request.
idstring:heavy_check_mark:The unique identifier of the guardrail550e8400-e29b-41d4-a716-446655440000
bulkAssignKeysRequestcomponents.BulkAssignKeysRequest:heavy_check_mark:N/A{"key_hashes": ["c56454edb818d6b14bc0d61c46025f1450b0f4012d12304ab40aacb519fcbc93"]}
opts[]operations.Option:heavy_minus_sign: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

go
package main import(	"context"	"os"	modelgates "github.com/ModelGatesTeam/go-sdk"	"github.com/ModelGatesTeam/go-sdk/models/components"	"log") func main() {    ctx := context.Background()     s := modelgates.New(        modelgates.WithSecurity(os.Getenv("MODELGATES_API_KEY")),    )     res, err := s.Guardrails.BulkUnassignKeys(ctx, "550e8400-e29b-41d4-a716-446655440000", components.BulkUnassignKeysRequest{        KeyHashes: []string{            "c56454edb818d6b14bc0d61c46025f1450b0f4012d12304ab40aacb519fcbc93",        },    })    if err != nil {        log.Fatal(err)    }    if res != nil {        // handle response    }}

Parameters

ParameterTypeRequiredDescriptionExample
ctxcontext.Context:heavy_check_mark:The context to use for the request.
idstring:heavy_check_mark:The unique identifier of the guardrail550e8400-e29b-41d4-a716-446655440000
bulkUnassignKeysRequestcomponents.BulkUnassignKeysRequest:heavy_check_mark:N/A{"key_hashes": ["c56454edb818d6b14bc0d61c46025f1450b0f4012d12304ab40aacb519fcbc93"]}
opts[]operations.Option:heavy_minus_sign: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

go
package main import(	"context"	"os"	modelgates "github.com/ModelGatesTeam/go-sdk"	"github.com/ModelGatesTeam/go-sdk/optionalnullable"	"log") func main() {    ctx := context.Background()     s := modelgates.New(        modelgates.WithSecurity(os.Getenv("MODELGATES_API_KEY")),    )     res, err := s.Guardrails.ListGuardrailMemberAssignments(ctx, "550e8400-e29b-41d4-a716-446655440000", optionalnullable.From[int64](nil), nil)    if err != nil {        log.Fatal(err)    }    if res != nil {        for {            // handle items             res, err = res.Next()             if err != nil {                // handle error            }             if res == nil {                break            }        }    }}

Parameters

ParameterTypeRequiredDescriptionExample
ctxcontext.Context:heavy_check_mark:The context to use for the request.
idstring:heavy_check_mark:The unique identifier of the guardrail550e8400-e29b-41d4-a716-446655440000
offsetoptionalnullable.OptionalNullable[int64]:heavy_minus_sign:Number of records to skip for pagination0
limit*int64:heavy_minus_sign:Maximum number of records to return (max 100)50
opts[]operations.Option:heavy_minus_sign: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

go
package main import(	"context"	"os"	modelgates "github.com/ModelGatesTeam/go-sdk"	"github.com/ModelGatesTeam/go-sdk/models/components"	"log") func main() {    ctx := context.Background()     s := modelgates.New(        modelgates.WithSecurity(os.Getenv("MODELGATES_API_KEY")),    )     res, err := s.Guardrails.BulkAssignMembers(ctx, "550e8400-e29b-41d4-a716-446655440000", components.BulkAssignMembersRequest{        MemberUserIds: []string{            "user_abc123",            "user_def456",        },    })    if err != nil {        log.Fatal(err)    }    if res != nil {        // handle response    }}

Parameters

ParameterTypeRequiredDescriptionExample
ctxcontext.Context:heavy_check_mark:The context to use for the request.
idstring:heavy_check_mark:The unique identifier of the guardrail550e8400-e29b-41d4-a716-446655440000
bulkAssignMembersRequestcomponents.BulkAssignMembersRequest:heavy_check_mark:N/A{"member_user_ids": ["user_abc123","user_def456"]}
opts[]operations.Option:heavy_minus_sign: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

go
package main import(	"context"	"os"	modelgates "github.com/ModelGatesTeam/go-sdk"	"github.com/ModelGatesTeam/go-sdk/models/components"	"log") func main() {    ctx := context.Background()     s := modelgates.New(        modelgates.WithSecurity(os.Getenv("MODELGATES_API_KEY")),    )     res, err := s.Guardrails.BulkUnassignMembers(ctx, "550e8400-e29b-41d4-a716-446655440000", components.BulkUnassignMembersRequest{        MemberUserIds: []string{            "user_abc123",            "user_def456",        },    })    if err != nil {        log.Fatal(err)    }    if res != nil {        // handle response    }}

Parameters

ParameterTypeRequiredDescriptionExample
ctxcontext.Context:heavy_check_mark:The context to use for the request.
idstring:heavy_check_mark:The unique identifier of the guardrail550e8400-e29b-41d4-a716-446655440000
bulkUnassignMembersRequestcomponents.BulkUnassignMembersRequest:heavy_check_mark:N/A{"member_user_ids": ["user_abc123","user_def456"]}
opts[]operations.Option:heavy_minus_sign: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

go
package main import(	"context"	"os"	modelgates "github.com/ModelGatesTeam/go-sdk"	"github.com/ModelGatesTeam/go-sdk/optionalnullable"	"log") func main() {    ctx := context.Background()     s := modelgates.New(        modelgates.WithSecurity(os.Getenv("MODELGATES_API_KEY")),    )     res, err := s.Guardrails.ListKeyAssignments(ctx, optionalnullable.From[int64](nil), nil)    if err != nil {        log.Fatal(err)    }    if res != nil {        for {            // handle items             res, err = res.Next()             if err != nil {                // handle error            }             if res == nil {                break            }        }    }}

Parameters

ParameterTypeRequiredDescriptionExample
ctxcontext.Context:heavy_check_mark:The context to use for the request.
offsetoptionalnullable.OptionalNullable[int64]:heavy_minus_sign:Number of records to skip for pagination0
limit*int64:heavy_minus_sign:Maximum number of records to return (max 100)50
opts[]operations.Option:heavy_minus_sign: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

go
package main import(	"context"	"os"	modelgates "github.com/ModelGatesTeam/go-sdk"	"github.com/ModelGatesTeam/go-sdk/optionalnullable"	"log") func main() {    ctx := context.Background()     s := modelgates.New(        modelgates.WithSecurity(os.Getenv("MODELGATES_API_KEY")),    )     res, err := s.Guardrails.ListMemberAssignments(ctx, optionalnullable.From[int64](nil), nil)    if err != nil {        log.Fatal(err)    }    if res != nil {        for {            // handle items             res, err = res.Next()             if err != nil {                // handle error            }             if res == nil {                break            }        }    }}

Parameters

ParameterTypeRequiredDescriptionExample
ctxcontext.Context:heavy_check_mark:The context to use for the request.
offsetoptionalnullable.OptionalNullable[int64]:heavy_minus_sign:Number of records to skip for pagination0
limit*int64:heavy_minus_sign:Maximum number of records to return (max 100)50
opts[]operations.Option:heavy_minus_sign:The options for this request.

Response

*operations.ListMemberAssignmentsResponse, error

Errors

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