> ## Documentation Index
> Fetch the complete documentation index at: https://openrouter.ai/docs/llms.txt
> Use this file to discover all available pages before exploring further.
# Workspaces
> Workspaces endpoints
## Overview
Workspaces endpoints
### Available Operations
* [List](#list) - List workspaces
* [Create](#create) - Create a workspace
* [Delete](#delete) - Delete a workspace
* [Get](#get) - Get a workspace
* [Update](#update) - Update a workspace
* [ListMembers](#listmembers) - List workspace members
* [BulkAddMembers](#bulkaddmembers) - Bulk add members to a workspace
* [BulkRemoveMembers](#bulkremovemembers) - Bulk remove members from a workspace
* [ListBudgets](#listbudgets) - List workspace budgets
* [DeleteBudget](#deletebudget) - Delete a workspace budget
* [GetBudget](#getbudget) - Get a workspace budget
* [SetBudget](#setbudget) - Create or update a workspace budget
## List
List all workspaces for the authenticated user. [Management key](/docs/client-sdks/go/docs/guides/overview/auth/management-api-keys) required.
### Example Usage
```go theme={null}
package main
import(
"context"
"os"
openrouter "github.com/OpenRouterTeam/go-sdk"
"github.com/OpenRouterTeam/go-sdk/optionalnullable"
"log"
)
func main() {
ctx := context.Background()
s := openrouter.New(
openrouter.WithSecurity(os.Getenv("OPENROUTER_API_KEY")),
)
res, err := s.Workspaces.List(ctx, optionalnullable.From(openrouter.Pointer[int64](0)), openrouter.Pointer[int64](50))
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
| Parameter | Type | Required | Description | Example |
| --------- | ---------------------------------------------------------- | -------------------- | --------------------------------------------- | ------- |
| `ctx` | [context.Context](https://pkg.go.dev/context#Context) | :heavy\_check\_mark: | The context to use for the request. | |
| `offset` | optionalnullable.OptionalNullable\[`int64`] | :heavy\_minus\_sign: | Number of records to skip for pagination | 0 |
| `limit` | `*int64` | :heavy\_minus\_sign: | Maximum number of records to return (max 100) | 50 |
| `opts` | \[][operations.Option](../../models/operations/option.mdx) | :heavy\_minus\_sign: | The options for this request. | |
### Response
**[\*operations.ListWorkspacesResponse](../../models/operations/listworkspacesresponse.mdx), error**
### Errors
| Error Type | Status Code | Content Type |
| ------------------------------------- | ----------- | ---------------- |
| sdkerrors.UnauthorizedResponseError | 401 | application/json |
| sdkerrors.InternalServerResponseError | 500 | application/json |
| sdkerrors.APIError | 4XX, 5XX | \*/\* |
## Create
Create a new workspace for the authenticated user. [Management key](/docs/client-sdks/go/docs/guides/overview/auth/management-api-keys) required.
### Example Usage
```go theme={null}
package main
import(
"context"
"os"
openrouter "github.com/OpenRouterTeam/go-sdk"
"github.com/OpenRouterTeam/go-sdk/optionalnullable"
"github.com/OpenRouterTeam/go-sdk/models/components"
"log"
)
func main() {
ctx := context.Background()
s := openrouter.New(
openrouter.WithSecurity(os.Getenv("OPENROUTER_API_KEY")),
)
res, err := s.Workspaces.Create(ctx, components.CreateWorkspaceRequest{
DefaultImageModel: optionalnullable.From(openrouter.Pointer("openai/dall-e-3")),
DefaultProviderSort: optionalnullable.From(openrouter.Pointer("price")),
DefaultTextModel: optionalnullable.From(openrouter.Pointer("openai/gpt-4o")),
Description: optionalnullable.From(openrouter.Pointer("Production environment workspace")),
Name: "Production",
Slug: "production",
})
if err != nil {
log.Fatal(err)
}
if res != nil {
// handle response
}
}
```
### Parameters
| Parameter | Type | Required | Description |
| --------- | --------------------------------------------------------------------------------------- | -------------------- | ------------------------------------------ |
| `ctx` | [context.Context](https://pkg.go.dev/context#Context) | :heavy\_check\_mark: | The context to use for the request. |
| `request` | [components.CreateWorkspaceRequest](../../models/components/createworkspacerequest.mdx) | :heavy\_check\_mark: | The request object to use for the request. |
| `opts` | \[][operations.Option](../../models/operations/option.mdx) | :heavy\_minus\_sign: | The options for this request. |
### Response
**[\*components.CreateWorkspaceResponse](../../models/components/createworkspaceresponse.mdx), error**
### Errors
| Error Type | Status Code | Content Type |
| ------------------------------------- | ----------- | ---------------- |
| sdkerrors.BadRequestResponseError | 400 | application/json |
| sdkerrors.UnauthorizedResponseError | 401 | application/json |
| sdkerrors.ForbiddenResponseError | 403 | application/json |
| sdkerrors.InternalServerResponseError | 500 | application/json |
| sdkerrors.APIError | 4XX, 5XX | \*/\* |
## Delete
Delete an existing workspace. Workspaces with active API keys cannot be deleted; remove the keys first. Deleting the default workspace requires confirm\_default\_workspace\_deletion=true. Deleting any workspace permanently deletes its budgets and guardrails and disables its classifiers and broadcast destinations. [Management key](/docs/client-sdks/go/docs/guides/overview/auth/management-api-keys) required.
### Example Usage
```go theme={null}
package main
import(
"context"
"os"
openrouter "github.com/OpenRouterTeam/go-sdk"
"log"
)
func main() {
ctx := context.Background()
s := openrouter.New(
openrouter.WithSecurity(os.Getenv("OPENROUTER_API_KEY")),
)
res, err := s.Workspaces.Delete(ctx, "production", nil)
if err != nil {
log.Fatal(err)
}
if res != nil {
// handle response
}
}
```
### Parameters
| Parameter | Type | Required | Description | Example |
| --------------------------------- | ---------------------------------------------------------- | -------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ---------- |
| `ctx` | [context.Context](https://pkg.go.dev/context#Context) | :heavy\_check\_mark: | The context to use for the request. | |
| `id` | `string` | :heavy\_check\_mark: | The workspace ID (UUID) or slug | production |
| `confirmDefaultWorkspaceDeletion` | `*bool` | :heavy\_minus\_sign: | Required to delete the default workspace. Deleting it permanently disables the account’s unscoped inference API keys (management/provisioning keys are retained) and its budgets, guardrails, classifiers, and broadcast destinations. Ignored for non-default workspaces. | false |
| `opts` | \[][operations.Option](../../models/operations/option.mdx) | :heavy\_minus\_sign: | The options for this request. | |
### Response
**[\*components.DeleteWorkspaceResponse](../../models/components/deleteworkspaceresponse.mdx), error**
### Errors
| Error Type | Status Code | Content Type |
| ------------------------------------- | ----------- | ---------------- |
| sdkerrors.BadRequestResponseError | 400 | application/json |
| sdkerrors.UnauthorizedResponseError | 401 | application/json |
| sdkerrors.ForbiddenResponseError | 403 | application/json |
| sdkerrors.NotFoundResponseError | 404 | application/json |
| sdkerrors.InternalServerResponseError | 500 | application/json |
| sdkerrors.APIError | 4XX, 5XX | \*/\* |
## Get
Get a single workspace by ID or slug. [Management key](/docs/client-sdks/go/docs/guides/overview/auth/management-api-keys) required.
### Example Usage
```go theme={null}
package main
import(
"context"
"os"
openrouter "github.com/OpenRouterTeam/go-sdk"
"log"
)
func main() {
ctx := context.Background()
s := openrouter.New(
openrouter.WithSecurity(os.Getenv("OPENROUTER_API_KEY")),
)
res, err := s.Workspaces.Get(ctx, "production")
if err != nil {
log.Fatal(err)
}
if res != nil {
// handle response
}
}
```
### Parameters
| Parameter | Type | Required | Description | Example |
| --------- | ---------------------------------------------------------- | -------------------- | ----------------------------------- | ---------- |
| `ctx` | [context.Context](https://pkg.go.dev/context#Context) | :heavy\_check\_mark: | The context to use for the request. | |
| `id` | `string` | :heavy\_check\_mark: | The workspace ID (UUID) or slug | production |
| `opts` | \[][operations.Option](../../models/operations/option.mdx) | :heavy\_minus\_sign: | The options for this request. | |
### Response
**[\*components.GetWorkspaceResponse](../../models/components/getworkspaceresponse.mdx), error**
### Errors
| Error Type | Status Code | Content Type |
| ------------------------------------- | ----------- | ---------------- |
| sdkerrors.UnauthorizedResponseError | 401 | application/json |
| sdkerrors.NotFoundResponseError | 404 | application/json |
| sdkerrors.InternalServerResponseError | 500 | application/json |
| sdkerrors.APIError | 4XX, 5XX | \*/\* |
## Update
Update an existing workspace by ID or slug. [Management key](/docs/client-sdks/go/docs/guides/overview/auth/management-api-keys) required.
### Example Usage
```go theme={null}
package main
import(
"context"
"os"
openrouter "github.com/OpenRouterTeam/go-sdk"
"github.com/OpenRouterTeam/go-sdk/models/components"
"log"
)
func main() {
ctx := context.Background()
s := openrouter.New(
openrouter.WithSecurity(os.Getenv("OPENROUTER_API_KEY")),
)
res, err := s.Workspaces.Update(ctx, "production", components.UpdateWorkspaceRequest{
Name: openrouter.Pointer("Updated Workspace"),
Slug: openrouter.Pointer("updated-workspace"),
})
if err != nil {
log.Fatal(err)
}
if res != nil {
// handle response
}
}
```
### Parameters
| Parameter | Type | Required | Description | Example |
| ------------------------ | --------------------------------------------------------------------------------------- | -------------------- | ----------------------------------- | ---------------------------------------------------------------------------- |
| `ctx` | [context.Context](https://pkg.go.dev/context#Context) | :heavy\_check\_mark: | The context to use for the request. | |
| `id` | `string` | :heavy\_check\_mark: | The workspace ID (UUID) or slug | production |
| `updateWorkspaceRequest` | [components.UpdateWorkspaceRequest](../../models/components/updateworkspacerequest.mdx) | :heavy\_check\_mark: | N/A | \{
"name": "Updated Workspace",
"slug": "updated-workspace"
} |
| `opts` | \[][operations.Option](../../models/operations/option.mdx) | :heavy\_minus\_sign: | The options for this request. | |
### Response
**[\*components.UpdateWorkspaceResponse](../../models/components/updateworkspaceresponse.mdx), error**
### Errors
| Error Type | Status Code | Content Type |
| ------------------------------------- | ----------- | ---------------- |
| sdkerrors.BadRequestResponseError | 400 | application/json |
| sdkerrors.UnauthorizedResponseError | 401 | application/json |
| sdkerrors.ForbiddenResponseError | 403 | application/json |
| sdkerrors.NotFoundResponseError | 404 | application/json |
| sdkerrors.InternalServerResponseError | 500 | application/json |
| sdkerrors.APIError | 4XX, 5XX | \*/\* |
## ListMembers
List all members of a workspace. Returns paginated results. For the default workspace, returns all organization members (implicit membership). [Management key](/docs/client-sdks/go/docs/guides/overview/auth/management-api-keys) required.
### Example Usage
```go theme={null}
package main
import(
"context"
"os"
openrouter "github.com/OpenRouterTeam/go-sdk"
"github.com/OpenRouterTeam/go-sdk/optionalnullable"
"log"
)
func main() {
ctx := context.Background()
s := openrouter.New(
openrouter.WithSecurity(os.Getenv("OPENROUTER_API_KEY")),
)
res, err := s.Workspaces.ListMembers(ctx, "production", optionalnullable.From(openrouter.Pointer[int64](0)), openrouter.Pointer[int64](50))
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
| Parameter | Type | Required | Description | Example |
| --------- | ---------------------------------------------------------- | -------------------- | --------------------------------------------- | ---------- |
| `ctx` | [context.Context](https://pkg.go.dev/context#Context) | :heavy\_check\_mark: | The context to use for the request. | |
| `id` | `string` | :heavy\_check\_mark: | The workspace ID (UUID) or slug | production |
| `offset` | optionalnullable.OptionalNullable\[`int64`] | :heavy\_minus\_sign: | Number of records to skip for pagination | 0 |
| `limit` | `*int64` | :heavy\_minus\_sign: | Maximum number of records to return (max 100) | 50 |
| `opts` | \[][operations.Option](../../models/operations/option.mdx) | :heavy\_minus\_sign: | The options for this request. | |
### Response
**[\*operations.ListWorkspaceMembersResponse](../../models/operations/listworkspacemembersresponse.mdx), error**
### Errors
| Error Type | Status Code | Content Type |
| ------------------------------------- | ----------- | ---------------- |
| sdkerrors.UnauthorizedResponseError | 401 | application/json |
| sdkerrors.ForbiddenResponseError | 403 | application/json |
| sdkerrors.NotFoundResponseError | 404 | application/json |
| sdkerrors.InternalServerResponseError | 500 | application/json |
| sdkerrors.APIError | 4XX, 5XX | \*/\* |
## BulkAddMembers
Add multiple organization members to a workspace. Members are assigned the same role they hold in the organization. [Management key](/docs/client-sdks/go/docs/guides/overview/auth/management-api-keys) required.
### Example Usage
```go theme={null}
package main
import(
"context"
"os"
openrouter "github.com/OpenRouterTeam/go-sdk"
"github.com/OpenRouterTeam/go-sdk/models/components"
"log"
)
func main() {
ctx := context.Background()
s := openrouter.New(
openrouter.WithSecurity(os.Getenv("OPENROUTER_API_KEY")),
)
res, err := s.Workspaces.BulkAddMembers(ctx, "production", components.BulkAddWorkspaceMembersRequest{
UserIds: []string{
"user_abc123",
"user_def456",
},
})
if err != nil {
log.Fatal(err)
}
if res != nil {
// handle response
}
}
```
### Parameters
| Parameter | Type | Required | Description | Example |
| -------------------------------- | ------------------------------------------------------------------------------------------------------- | -------------------- | ----------------------------------- | ------------------------------------------------------------------------------ |
| `ctx` | [context.Context](https://pkg.go.dev/context#Context) | :heavy\_check\_mark: | The context to use for the request. | |
| `id` | `string` | :heavy\_check\_mark: | The workspace ID (UUID) or slug | production |
| `bulkAddWorkspaceMembersRequest` | [components.BulkAddWorkspaceMembersRequest](../../models/components/bulkaddworkspacemembersrequest.mdx) | :heavy\_check\_mark: | N/A | \{
"user\_ids": \[
"user\_abc123",
"user\_def456"
]
} |
| `opts` | \[][operations.Option](../../models/operations/option.mdx) | :heavy\_minus\_sign: | The options for this request. | |
### Response
**[\*components.BulkAddWorkspaceMembersResponse](../../models/components/bulkaddworkspacemembersresponse.mdx), error**
### Errors
| Error Type | Status Code | Content Type |
| ------------------------------------- | ----------- | ---------------- |
| sdkerrors.BadRequestResponseError | 400 | application/json |
| sdkerrors.UnauthorizedResponseError | 401 | application/json |
| sdkerrors.ForbiddenResponseError | 403 | application/json |
| sdkerrors.NotFoundResponseError | 404 | application/json |
| sdkerrors.InternalServerResponseError | 500 | application/json |
| sdkerrors.APIError | 4XX, 5XX | \*/\* |
## BulkRemoveMembers
Remove multiple members from a workspace. Members with active API keys in the workspace cannot be removed. SCIM-managed members cannot be removed; changes must be made in your identity provider. [Management key](/docs/client-sdks/go/docs/guides/overview/auth/management-api-keys) required.
### Example Usage
```go theme={null}
package main
import(
"context"
"os"
openrouter "github.com/OpenRouterTeam/go-sdk"
"github.com/OpenRouterTeam/go-sdk/models/components"
"log"
)
func main() {
ctx := context.Background()
s := openrouter.New(
openrouter.WithSecurity(os.Getenv("OPENROUTER_API_KEY")),
)
res, err := s.Workspaces.BulkRemoveMembers(ctx, "production", components.BulkRemoveWorkspaceMembersRequest{
UserIds: []string{
"user_abc123",
"user_def456",
},
})
if err != nil {
log.Fatal(err)
}
if res != nil {
// handle response
}
}
```
### Parameters
| Parameter | Type | Required | Description | Example |
| ----------------------------------- | ------------------------------------------------------------------------------------------------------------- | -------------------- | ----------------------------------- | ------------------------------------------------------------------------------ |
| `ctx` | [context.Context](https://pkg.go.dev/context#Context) | :heavy\_check\_mark: | The context to use for the request. | |
| `id` | `string` | :heavy\_check\_mark: | The workspace ID (UUID) or slug | production |
| `bulkRemoveWorkspaceMembersRequest` | [components.BulkRemoveWorkspaceMembersRequest](../../models/components/bulkremoveworkspacemembersrequest.mdx) | :heavy\_check\_mark: | N/A | \{
"user\_ids": \[
"user\_abc123",
"user\_def456"
]
} |
| `opts` | \[][operations.Option](../../models/operations/option.mdx) | :heavy\_minus\_sign: | The options for this request. | |
### Response
**[\*components.BulkRemoveWorkspaceMembersResponse](../../models/components/bulkremoveworkspacemembersresponse.mdx), error**
### Errors
| Error Type | Status Code | Content Type |
| ------------------------------------- | ----------- | ---------------- |
| sdkerrors.BadRequestResponseError | 400 | application/json |
| sdkerrors.UnauthorizedResponseError | 401 | application/json |
| sdkerrors.ForbiddenResponseError | 403 | application/json |
| sdkerrors.NotFoundResponseError | 404 | application/json |
| sdkerrors.InternalServerResponseError | 500 | application/json |
| sdkerrors.APIError | 4XX, 5XX | \*/\* |
## ListBudgets
List all budgets configured for a workspace. [Management key](/docs/client-sdks/go/docs/guides/overview/auth/management-api-keys) required.
### Example Usage
```go theme={null}
package main
import(
"context"
"os"
openrouter "github.com/OpenRouterTeam/go-sdk"
"log"
)
func main() {
ctx := context.Background()
s := openrouter.New(
openrouter.WithSecurity(os.Getenv("OPENROUTER_API_KEY")),
)
res, err := s.Workspaces.ListBudgets(ctx, "production")
if err != nil {
log.Fatal(err)
}
if res != nil {
// handle response
}
}
```
### Parameters
| Parameter | Type | Required | Description | Example |
| -------------- | ---------------------------------------------------------- | -------------------- | ----------------------------------- | ---------- |
| `ctx` | [context.Context](https://pkg.go.dev/context#Context) | :heavy\_check\_mark: | The context to use for the request. | |
| `workspaceRef` | `string` | :heavy\_check\_mark: | The workspace ID (UUID) or slug | production |
| `opts` | \[][operations.Option](../../models/operations/option.mdx) | :heavy\_minus\_sign: | The options for this request. | |
### Response
**[\*components.ListWorkspaceBudgetsResponse](../../models/components/listworkspacebudgetsresponse.mdx), error**
### Errors
| Error Type | Status Code | Content Type |
| ------------------------------------- | ----------- | ---------------- |
| sdkerrors.UnauthorizedResponseError | 401 | application/json |
| sdkerrors.NotFoundResponseError | 404 | application/json |
| sdkerrors.InternalServerResponseError | 500 | application/json |
| sdkerrors.APIError | 4XX, 5XX | \*/\* |
## DeleteBudget
Remove the budget for a given interval. [Management key](/docs/client-sdks/go/docs/guides/overview/auth/management-api-keys) required.
### Example Usage
```go theme={null}
package main
import(
"context"
"os"
openrouter "github.com/OpenRouterTeam/go-sdk"
"github.com/OpenRouterTeam/go-sdk/models/components"
"log"
)
func main() {
ctx := context.Background()
s := openrouter.New(
openrouter.WithSecurity(os.Getenv("OPENROUTER_API_KEY")),
)
res, err := s.Workspaces.DeleteBudget(ctx, "production", components.WorkspaceBudgetIntervalMonthly)
if err != nil {
log.Fatal(err)
}
if res != nil {
// handle response
}
}
```
### Parameters
| Parameter | Type | Required | Description | Example |
| -------------- | ----------------------------------------------------------------------------------------- | -------------------- | ------------------------------------------------------------------------------ | ---------- |
| `ctx` | [context.Context](https://pkg.go.dev/context#Context) | :heavy\_check\_mark: | The context to use for the request. | |
| `workspaceRef` | `string` | :heavy\_check\_mark: | The workspace ID (UUID) or slug | production |
| `interval` | [components.WorkspaceBudgetInterval](../../models/components/workspacebudgetinterval.mdx) | :heavy\_check\_mark: | Budget reset interval. Use "lifetime" for a one-time budget that never resets. | monthly |
| `opts` | \[][operations.Option](../../models/operations/option.mdx) | :heavy\_minus\_sign: | The options for this request. | |
### Response
**[\*components.DeleteWorkspaceBudgetResponse](../../models/components/deleteworkspacebudgetresponse.mdx), error**
### Errors
| Error Type | Status Code | Content Type |
| ------------------------------------- | ----------- | ---------------- |
| sdkerrors.BadRequestResponseError | 400 | application/json |
| sdkerrors.UnauthorizedResponseError | 401 | application/json |
| sdkerrors.NotFoundResponseError | 404 | application/json |
| sdkerrors.InternalServerResponseError | 500 | application/json |
| sdkerrors.APIError | 4XX, 5XX | \*/\* |
## GetBudget
Retrieve the budget for a given interval. [Management key](/docs/client-sdks/go/docs/guides/overview/auth/management-api-keys) required.
### Example Usage
```go theme={null}
package main
import(
"context"
"os"
openrouter "github.com/OpenRouterTeam/go-sdk"
"github.com/OpenRouterTeam/go-sdk/models/components"
"log"
)
func main() {
ctx := context.Background()
s := openrouter.New(
openrouter.WithSecurity(os.Getenv("OPENROUTER_API_KEY")),
)
res, err := s.Workspaces.GetBudget(ctx, "production", components.WorkspaceBudgetIntervalMonthly)
if err != nil {
log.Fatal(err)
}
if res != nil {
// handle response
}
}
```
### Parameters
| Parameter | Type | Required | Description | Example |
| -------------- | ----------------------------------------------------------------------------------------- | -------------------- | ------------------------------------------------------------------------------ | ---------- |
| `ctx` | [context.Context](https://pkg.go.dev/context#Context) | :heavy\_check\_mark: | The context to use for the request. | |
| `workspaceRef` | `string` | :heavy\_check\_mark: | The workspace ID (UUID) or slug | production |
| `interval` | [components.WorkspaceBudgetInterval](../../models/components/workspacebudgetinterval.mdx) | :heavy\_check\_mark: | Budget reset interval. Use "lifetime" for a one-time budget that never resets. | monthly |
| `opts` | \[][operations.Option](../../models/operations/option.mdx) | :heavy\_minus\_sign: | The options for this request. | |
### Response
**[\*components.GetWorkspaceBudgetResponse](../../models/components/getworkspacebudgetresponse.mdx), error**
### Errors
| Error Type | Status Code | Content Type |
| ------------------------------------- | ----------- | ---------------- |
| sdkerrors.BadRequestResponseError | 400 | application/json |
| sdkerrors.UnauthorizedResponseError | 401 | application/json |
| sdkerrors.NotFoundResponseError | 404 | application/json |
| sdkerrors.InternalServerResponseError | 500 | application/json |
| sdkerrors.APIError | 4XX, 5XX | \*/\* |
## SetBudget
Create or update the budget for a given interval. Budget limits must strictly decrease as the interval narrows (lifetime > monthly > weekly > daily). The optional `include_byok_in_budgets` flag is a workspace-wide setting: when provided it applies to every budget interval for the workspace, not just the interval in this request. Note that a change made here is applied to budget enforcement immediately, but an already-open workspace settings page in the web dashboard may keep showing the previous value until it is reloaded. [Management key](/docs/client-sdks/go/docs/guides/overview/auth/management-api-keys) required.
### Example Usage
```go theme={null}
package main
import(
"context"
"os"
openrouter "github.com/OpenRouterTeam/go-sdk"
"github.com/OpenRouterTeam/go-sdk/models/components"
"log"
)
func main() {
ctx := context.Background()
s := openrouter.New(
openrouter.WithSecurity(os.Getenv("OPENROUTER_API_KEY")),
)
res, err := s.Workspaces.SetBudget(ctx, "production", components.WorkspaceBudgetIntervalMonthly, components.UpsertWorkspaceBudgetRequest{
IncludeBYOKInBudgets: openrouter.Pointer(true),
LimitUsd: 100.0,
})
if err != nil {
log.Fatal(err)
}
if res != nil {
// handle response
}
}
```
### Parameters
| Parameter | Type | Required | Description | Example |
| ------------------------------ | --------------------------------------------------------------------------------------------------- | -------------------- | ------------------------------------------------------------------------------ | ------------------------------------------------------------------------- |
| `ctx` | [context.Context](https://pkg.go.dev/context#Context) | :heavy\_check\_mark: | The context to use for the request. | |
| `workspaceRef` | `string` | :heavy\_check\_mark: | The workspace ID (UUID) or slug | production |
| `interval` | [components.WorkspaceBudgetInterval](../../models/components/workspacebudgetinterval.mdx) | :heavy\_check\_mark: | Budget reset interval. Use "lifetime" for a one-time budget that never resets. | monthly |
| `upsertWorkspaceBudgetRequest` | [components.UpsertWorkspaceBudgetRequest](../../models/components/upsertworkspacebudgetrequest.mdx) | :heavy\_check\_mark: | N/A | \{
"include\_byok\_in\_budgets": true,
"limit\_usd": 100
} |
| `opts` | \[][operations.Option](../../models/operations/option.mdx) | :heavy\_minus\_sign: | The options for this request. | |
### Response
**[\*components.UpsertWorkspaceBudgetResponse](../../models/components/upsertworkspacebudgetresponse.mdx), error**
### Errors
| Error Type | Status Code | Content Type |
| ------------------------------------- | ----------- | ---------------- |
| sdkerrors.BadRequestResponseError | 400 | application/json |
| sdkerrors.UnauthorizedResponseError | 401 | application/json |
| sdkerrors.NotFoundResponseError | 404 | application/json |
| sdkerrors.InternalServerResponseError | 500 | application/json |
| sdkerrors.APIError | 4XX, 5XX | \*/\* |