For AI client integration (Claude Code, Cursor, etc.), connect to the MCP server at https://modelgates.ai/docs/_mcp/server.
APIKeys - Go SDK
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
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.APIKeys.GetCurrentKeyMetadata(ctx) if err != nil { log.Fatal(err) } if res != nil { // handle response }}Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
ctx | context.Context | :heavy_check_mark: | The context to use for the request. |
opts | []operations.Option | :heavy_minus_sign: | The options for this request. |
Response
*operations.GetCurrentKeyResponse, 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 required.
Example Usage
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.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 | :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 | :heavy_minus_sign: | The options for this request. |
Response
*operations.ListResponse, error
Errors
| Error Type | Status Code | Content Type |
|---|---|---|
| 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. Management key required.
Example Usage
package main import( "context" "os" modelgates "github.com/ModelGatesTeam/go-sdk" "github.com/ModelGatesTeam/go-sdk/types" "github.com/ModelGatesTeam/go-sdk/optionalnullable" "github.com/ModelGatesTeam/go-sdk/models/operations" "log") func main() { ctx := context.Background() s := modelgates.New( modelgates.WithSecurity(os.Getenv("MODELGATES_API_KEY")), ) res, err := s.APIKeys.Create(ctx, operations.CreateKeysRequest{ ExpiresAt: optionalnullable.From(modelgates.Pointer(types.MustNewTimeFromString("2027-12-31T23:59:59Z"))), IncludeByokInLimit: modelgates.Pointer(true), Limit: optionalnullable.From(modelgates.Pointer[float64](50.0)), LimitReset: optionalnullable.From(modelgates.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 | :heavy_check_mark: | The context to use for the request. |
request | operations.CreateKeysRequest | :heavy_check_mark: | The request object to use for the request. |
opts | []operations.Option | :heavy_minus_sign: | The options for this request. |
Response
*operations.CreateKeysResponse, 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. Management key required.
Example Usage
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.APIKeys.Delete(ctx, "f01d52606dc8f0a8303a7b5cc3fa07109c2e346cec7c0a16b40de462992ce943") if err != nil { log.Fatal(err) } if res != nil { // handle response }}Parameters
| Parameter | Type | Required | Description | Example |
|---|---|---|---|---|
ctx | 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 | :heavy_minus_sign: | The options for this request. |
Response
*operations.DeleteKeysResponse, 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 required.
Example Usage
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.APIKeys.Get(ctx, "f01d52606dc8f0a8303a7b5cc3fa07109c2e346cec7c0a16b40de462992ce943") if err != nil { log.Fatal(err) } if res != nil { // handle response }}Parameters
| Parameter | Type | Required | Description | Example |
|---|---|---|---|---|
ctx | 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 | :heavy_minus_sign: | The options for this request. |
Response
*operations.GetKeyResponse, 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. Management key required.
Example Usage
package main import( "context" "os" modelgates "github.com/ModelGatesTeam/go-sdk" "github.com/ModelGatesTeam/go-sdk/optionalnullable" "github.com/ModelGatesTeam/go-sdk/models/operations" "log") func main() { ctx := context.Background() s := modelgates.New( modelgates.WithSecurity(os.Getenv("MODELGATES_API_KEY")), ) res, err := s.APIKeys.Update(ctx, "f01d52606dc8f0a8303a7b5cc3fa07109c2e346cec7c0a16b40de462992ce943", operations.UpdateKeysRequestBody{ Disabled: modelgates.Pointer(false), IncludeByokInLimit: modelgates.Pointer(true), Limit: optionalnullable.From(modelgates.Pointer[float64](75.0)), LimitReset: optionalnullable.From(modelgates.Pointer(operations.UpdateKeysLimitResetDaily)), Name: modelgates.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 | :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 | :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 | :heavy_minus_sign: | The options for this request. |
Response
*operations.UpdateKeysResponse, 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 | */* |