A bucket of owned compute balance over time.
- List - List capacities
- Create - Create capacity
- Fetch - Get capacity
- Delete - Delete capacity
- Update - Update capacity
- ListCapacityTransfers - List capacity transfers
- CreateCapacityTransfer - Create capacity transfer
- FetchCapacityTransfer - Get capacity transfer
List all capacities.
package main
import(
"context"
sfc "github.com/sfcompute/sfc-go"
"github.com/sfcompute/sfc-go/models/operations"
"log"
)
func main() {
ctx := context.Background()
s := sfc.New(
sfc.WithSecurity("<YOUR_BEARER_TOKEN_HERE>"),
)
res, err := s.Capacities.List(ctx, operations.ListCapacitiesRequest{
Workspace: "wksp_k3R-nX9vLm7Qp2Yw5Jd8F",
ID: []string{
"cap_k3R-nX9vLm7Qp2Yw5Jd8F",
},
StartingAfter: sfc.Pointer("capc_gqXR7s0Kj5mHvE2wNpLc4Q"),
EndingBefore: sfc.Pointer("capc_gqXR7s0Kj5mHvE2wNpLc4Q"),
})
if err != nil {
log.Fatal(err)
}
if res.ListCapacitiesResponse != nil {
for {
// handle items
res, err = res.Next()
if err != nil {
// handle error
}
if res == nil {
break
}
}
}
}| Parameter | Type | Required | Description |
|---|---|---|---|
ctx |
context.Context | ✔️ | The context to use for the request. |
request |
operations.ListCapacitiesRequest | ✔️ | The request object to use for the request. |
opts |
[]operations.Option | ➖ | The options for this request. |
*operations.ListCapacitiesResponse, error
| Error Type | Status Code | Content Type |
|---|---|---|
| apierrors.UnauthorizedError | 401 | application/json |
| apierrors.UnprocessableEntityError | 422 | application/json |
| apierrors.InternalServerError | 500 | application/json |
| apierrors.APIError | 4XX, 5XX | */* |
Create a capacity to hold compute.
package main
import(
"context"
sfc "github.com/sfcompute/sfc-go"
"github.com/sfcompute/sfc-go/optionalnullable"
"github.com/sfcompute/sfc-go/models/components"
"log"
)
func main() {
ctx := context.Background()
s := sfc.New(
sfc.WithSecurity("<YOUR_BEARER_TOKEN_HERE>"),
)
res, err := s.Capacities.Create(ctx, components.CreateCapacityRequest{
Name: optionalnullable.From(sfc.Pointer("my-resource-name")),
Workspace: "wksp_k3R-nX9vLm7Qp2Yw5Jd8F",
Tags: optionalnullable.From(sfc.Pointer(map[string]string{
"env": "prod",
"team": "infra",
})),
})
if err != nil {
log.Fatal(err)
}
if res.CapacityResponse != nil {
switch res.CapacityResponse.Procurements.Type {
case components.ExpandableListProcurementIDProcurementSummaryUnionTypeArrayOfStr:
// res.CapacityResponse.Procurements.ArrayOfStr is populated
case components.ExpandableListProcurementIDProcurementSummaryUnionTypeArrayOfExpandableListProcurementIDProcurementSummary:
// res.CapacityResponse.Procurements.ArrayOfExpandableListProcurementIDProcurementSummary is populated
default:
// Unknown type - use res.CapacityResponse.Procurements.GetUnknownRaw() for raw JSON
}
}
}| Parameter | Type | Required | Description |
|---|---|---|---|
ctx |
context.Context | ✔️ | The context to use for the request. |
request |
components.CreateCapacityRequest | ✔️ | The request object to use for the request. |
opts |
[]operations.Option | ➖ | The options for this request. |
*operations.CreateCapacityResponse, error
| Error Type | Status Code | Content Type |
|---|---|---|
| apierrors.UnauthorizedError | 401 | application/json |
| apierrors.ForbiddenError | 403 | application/json |
| apierrors.UnprocessableEntityError | 422 | application/json |
| apierrors.InternalServerError | 500 | application/json |
| apierrors.APIError | 4XX, 5XX | */* |
Retrieve a capacity by ID, resource path, or name, including its compute schedule.
package main
import(
"context"
sfc "github.com/sfcompute/sfc-go"
"log"
"github.com/sfcompute/sfc-go/models/components"
)
func main() {
ctx := context.Background()
s := sfc.New(
sfc.WithSecurity("<YOUR_BEARER_TOKEN_HERE>"),
)
res, err := s.Capacities.Fetch(ctx, "cap_k3R-nX9vLm7Qp2Yw5Jd8F", sfc.Pointer[int64](0), nil)
if err != nil {
log.Fatal(err)
}
if res.CapacityResponse != nil {
switch res.CapacityResponse.Procurements.Type {
case components.ExpandableListProcurementIDProcurementSummaryUnionTypeArrayOfStr:
// res.CapacityResponse.Procurements.ArrayOfStr is populated
case components.ExpandableListProcurementIDProcurementSummaryUnionTypeArrayOfExpandableListProcurementIDProcurementSummary:
// res.CapacityResponse.Procurements.ArrayOfExpandableListProcurementIDProcurementSummary is populated
default:
// Unknown type - use res.CapacityResponse.Procurements.GetUnknownRaw() for raw JSON
}
}
}| Parameter | Type | Required | Description | Example |
|---|---|---|---|---|
ctx |
context.Context | ✔️ | The context to use for the request. | |
id |
string |
✔️ | N/A | cap_k3R-nX9vLm7Qp2Yw5Jd8F |
scheduleHistoryMinutes |
*int64 |
➖ | How many minutes of past schedule to include. | |
expand |
[]operations.FetchCapacityExpand | ➖ | Expand related resources inline instead of returning IDs. | |
opts |
[]operations.Option | ➖ | The options for this request. |
*operations.FetchCapacityResponse, error
| Error Type | Status Code | Content Type |
|---|---|---|
| apierrors.UnauthorizedError | 401 | application/json |
| apierrors.NotFoundError | 404 | application/json |
| apierrors.InternalServerError | 500 | application/json |
| apierrors.APIError | 4XX, 5XX | */* |
Delete a capacity. The capacity must have no active orders, future allocations, active nodes, deployments, or procurements. Remove all dependencies before deleting.
package main
import(
"context"
sfc "github.com/sfcompute/sfc-go"
"log"
)
func main() {
ctx := context.Background()
s := sfc.New(
sfc.WithSecurity("<YOUR_BEARER_TOKEN_HERE>"),
)
res, err := s.Capacities.Delete(ctx, "cap_k3R-nX9vLm7Qp2Yw5Jd8F")
if err != nil {
log.Fatal(err)
}
if res != nil {
// handle response
}
}| Parameter | Type | Required | Description | Example |
|---|---|---|---|---|
ctx |
context.Context | ✔️ | The context to use for the request. | |
id |
string |
✔️ | N/A | cap_k3R-nX9vLm7Qp2Yw5Jd8F |
opts |
[]operations.Option | ➖ | The options for this request. |
*operations.DeleteCapacityResponse, error
| Error Type | Status Code | Content Type |
|---|---|---|
| apierrors.UnauthorizedError | 401 | application/json |
| apierrors.NotFoundError | 404 | application/json |
| apierrors.UnprocessableEntityError | 422 | application/json |
| apierrors.InternalServerError | 500 | application/json |
| apierrors.APIError | 4XX, 5XX | */* |
Update a capacity. Omitted fields are left unchanged.
package main
import(
"context"
sfc "github.com/sfcompute/sfc-go"
"github.com/sfcompute/sfc-go/optionalnullable"
"github.com/sfcompute/sfc-go/models/components"
"log"
)
func main() {
ctx := context.Background()
s := sfc.New(
sfc.WithSecurity("<YOUR_BEARER_TOKEN_HERE>"),
)
res, err := s.Capacities.Update(ctx, "cap_k3R-nX9vLm7Qp2Yw5Jd8F", components.PatchCapacityRequest{
Name: optionalnullable.From(sfc.Pointer("my-resource-name")),
Tags: optionalnullable.From(sfc.Pointer(map[string]string{
"env": "prod",
"team": "infra",
})),
})
if err != nil {
log.Fatal(err)
}
if res.CapacityResponse != nil {
switch res.CapacityResponse.Procurements.Type {
case components.ExpandableListProcurementIDProcurementSummaryUnionTypeArrayOfStr:
// res.CapacityResponse.Procurements.ArrayOfStr is populated
case components.ExpandableListProcurementIDProcurementSummaryUnionTypeArrayOfExpandableListProcurementIDProcurementSummary:
// res.CapacityResponse.Procurements.ArrayOfExpandableListProcurementIDProcurementSummary is populated
default:
// Unknown type - use res.CapacityResponse.Procurements.GetUnknownRaw() for raw JSON
}
}
}| Parameter | Type | Required | Description | Example |
|---|---|---|---|---|
ctx |
context.Context | ✔️ | The context to use for the request. | |
id |
string |
✔️ | N/A | cap_k3R-nX9vLm7Qp2Yw5Jd8F |
body |
components.PatchCapacityRequest | ✔️ | N/A | |
opts |
[]operations.Option | ➖ | The options for this request. |
*operations.UpdateCapacityResponse, error
| Error Type | Status Code | Content Type |
|---|---|---|
| apierrors.UnauthorizedError | 401 | application/json |
| apierrors.ForbiddenError | 403 | application/json |
| apierrors.NotFoundError | 404 | application/json |
| apierrors.UnprocessableEntityError | 422 | application/json |
| apierrors.InternalServerError | 500 | application/json |
| apierrors.APIError | 4XX, 5XX | */* |
List capacity transfers for the caller's organization.
package main
import(
"context"
sfc "github.com/sfcompute/sfc-go"
"github.com/sfcompute/sfc-go/models/operations"
"log"
)
func main() {
ctx := context.Background()
s := sfc.New(
sfc.WithSecurity("<YOUR_BEARER_TOKEN_HERE>"),
)
res, err := s.Capacities.ListCapacityTransfers(ctx, operations.ListCapacityTransfersRequest{
Capacity: []string{
"cap_k3R-nX9vLm7Qp2Yw5Jd8F",
},
StartingAfter: sfc.Pointer("ctfrc_gqXR7s0Kj5mHvE2wNpLc4Q"),
EndingBefore: sfc.Pointer("ctfrc_gqXR7s0Kj5mHvE2wNpLc4Q"),
})
if err != nil {
log.Fatal(err)
}
if res.V2ListCapacityTransfersResponse != nil {
for {
// handle items
res, err = res.Next()
if err != nil {
// handle error
}
if res == nil {
break
}
}
}
}| Parameter | Type | Required | Description |
|---|---|---|---|
ctx |
context.Context | ✔️ | The context to use for the request. |
request |
operations.ListCapacityTransfersRequest | ✔️ | The request object to use for the request. |
opts |
[]operations.Option | ➖ | The options for this request. |
*operations.ListCapacityTransfersResponse, error
| Error Type | Status Code | Content Type |
|---|---|---|
| apierrors.UnauthorizedError | 401 | application/json |
| apierrors.UnprocessableEntityError | 422 | application/json |
| apierrors.InternalServerError | 500 | application/json |
| apierrors.APIError | 4XX, 5XX | */* |
Transfer some or all of one capacity into another
package main
import(
"context"
sfc "github.com/sfcompute/sfc-go"
"github.com/sfcompute/sfc-go/optionalnullable"
"github.com/sfcompute/sfc-go/models/components"
"log"
)
func main() {
ctx := context.Background()
s := sfc.New(
sfc.WithSecurity("<YOUR_BEARER_TOKEN_HERE>"),
)
res, err := s.Capacities.CreateCapacityTransfer(ctx, components.V2CreateCapacityTransferRequest{
FromCapacity: "cap_k3R-nX9vLm7Qp2Yw5Jd8F",
ToCapacity: "cap_k3R-nX9vLm7Qp2Yw5Jd8F",
AllocationScheduleDelta: []components.V2AllocationScheduleDelta{
components.V2AllocationScheduleDelta{
NodeCount: 569495,
StartAt: 1738972800,
EndAt: optionalnullable.From(sfc.Pointer[int64](1738972800)),
},
},
InstanceSku: "isku_k3R-nX9vLm7Qp2Yw5Jd8F",
}, optionalnullable.From[string](nil))
if err != nil {
log.Fatal(err)
}
if res.V2CapacityTransferResponse != nil {
// handle response
}
}| Parameter | Type | Required | Description |
|---|---|---|---|
ctx |
context.Context | ✔️ | The context to use for the request. |
body |
components.V2CreateCapacityTransferRequest | ✔️ | N/A |
idempotencyKey |
optionalnullable.OptionalNullable[string] |
➖ | Unique key for idempotent transfer creation. |
opts |
[]operations.Option | ➖ | The options for this request. |
*operations.CreateCapacityTransferResponse, error
| Error Type | Status Code | Content Type |
|---|---|---|
| apierrors.UnauthorizedError | 401 | application/json |
| apierrors.ForbiddenError | 403 | application/json |
| apierrors.NotFoundError | 404 | application/json |
| apierrors.UnprocessableEntityError | 422 | application/json |
| apierrors.InternalServerError | 500 | application/json |
| apierrors.ServiceUnavailableError | 503 | application/json |
| apierrors.APIError | 4XX, 5XX | */* |
Retrieve a capacity transfer by ID.
package main
import(
"context"
sfc "github.com/sfcompute/sfc-go"
"log"
)
func main() {
ctx := context.Background()
s := sfc.New(
sfc.WithSecurity("<YOUR_BEARER_TOKEN_HERE>"),
)
res, err := s.Capacities.FetchCapacityTransfer(ctx, "cxfr_abc123")
if err != nil {
log.Fatal(err)
}
if res.V2CapacityTransferResponse != nil {
// handle response
}
}| Parameter | Type | Required | Description | Example |
|---|---|---|---|---|
ctx |
context.Context | ✔️ | The context to use for the request. | |
id |
string |
✔️ | Capacity transfer ID | cxfr_k3R-nX9vLm7Qp2Yw5Jd8F |
opts |
[]operations.Option | ➖ | The options for this request. |
*operations.FetchCapacityTransferResponse, error
| Error Type | Status Code | Content Type |
|---|---|---|
| apierrors.UnauthorizedError | 401 | application/json |
| apierrors.NotFoundError | 404 | application/json |
| apierrors.InternalServerError | 500 | application/json |
| apierrors.APIError | 4XX, 5XX | */* |