# Reservations (/docs/go-sdk/reservations)

> For AI agents: the complete documentation index is at https://www.daytona.com/llms.txt.

## Reservations [#reservations]

```go
type Reservations struct {
	// contains filtered or unexported fields
}
```

Reservations manages dedicated Macs billed in 24-hour periods.
Obtain it from Client.Reservations. Purchases, renewals and enabling auto-renew
need macOS access (ErrFeatureNotEnabled); reads and disabling auto-renew do not.

#### Reservations.Create [#reservationscreate]

```go
func (s *Reservations) Create(
	ctx context.Context, region string, opts *CreateReservationOptions,
) (*MacReservation, error)
```

Create purchases one Mac in region. Blank region is sent unchanged.
Nil options select the region's default model and organization's renewal policy.
Reuse an explicit idempotency key after a lost response to avoid buying twice.
ErrNoMacAvailable means no matching Mac is free; ErrLimitExceeded reports the
organization's reservation limit. This call does not wait for activation.

**Example**:

```go
client, err := daytona.New()
if err != nil {
	log.Print(err)
	return
}
defer func() {
	if closeErr := client.Close(); closeErr != nil {
		log.Print(closeErr)
	}
}()
autoRenew := false
// This purchases a billed reservation. Reuse the same key and options if
// retrying after a lost response; do not generate a new key for that retry.
reservation, err := client.Reservations().Create(context.Background(), "region-id", &daytona.CreateReservationOptions{
	IdempotencyKey: "my-purchase-request", AutoRenew: &autoRenew,
})
if err != nil {
	log.Print(err)
	return
}
fmt.Println(reservation.ID, reservation.Status, reservation.Period)
```

#### Reservations.CreateBulk [#reservationscreatebulk]

```go
func (s *Reservations) CreateBulk(
	ctx context.Context, region string, count int, opts *CreateReservationsBulkOptions,
) (*MacReservationBatch, error)
```

CreateBulk purchases count Macs of one model in region. Count must be 1–100.
MinCount defaults to count (all or nothing). A partial purchase is allowed
only when at least MinCount Macs fit both availability and organization limits.
ErrLimitExceeded is checked by the server before ErrNoMacAvailable.
Reuse an explicit idempotency key after a lost response to avoid buying twice.
Invalid counts or header values return ErrBadRequest before any request.

**Example**:

```go
client, err := daytona.New()
if err != nil {
	log.Print(err)
	return
}
defer func() {
	if closeErr := client.Close(); closeErr != nil {
		log.Print(closeErr)
	}
}()
// Purchase up to three Macs, accepting no fewer than two.
batch, err := client.Reservations().CreateBulk(
	context.Background(), "region-id", 3, &daytona.CreateReservationsBulkOptions{
		MinCount: 2, IdempotencyKey: "my-bulk-purchase",
	},
)
if err != nil {
	log.Print(err)
	return
}
fmt.Println(batch.Requested, batch.Reserved)
```

#### Reservations.Get [#reservationsget]

```go
func (s *Reservations) Get(ctx context.Context, id string) (*MacReservation, error)
```

Get reads one reservation. A missing reservation returns ErrReservationNotFound.
Invalid path identifiers return ErrBadRequest before any request.

#### Reservations.List [#reservationslist]

```go
func (s *Reservations) List(ctx context.Context, opts *ListReservationsOptions) (*Page[MacReservation], error)
```

List returns exactly one page of the organization's reservations.
Invalid cursor encoding or a limit outside 1–200 returns ErrBadRequest;
zero Limit selects the server default.

#### Reservations.ListAll [#reservationslistall]

```go
func (s *Reservations) ListAll(ctx context.Context, opts *ListReservationsOptions) iter.Seq2[MacReservation, error]
```

ListAll lazily traverses reservations, stopping on cancellation, an error,
exhaustion or a repeated cursor. Options are copied now; breaking iteration
makes no further requests. An error is yielded once.

**Example**:

```go
client, err := daytona.New()
if err != nil {
	log.Print(err)
	return
}
defer func() {
	if closeErr := client.Close(); closeErr != nil {
		log.Print(closeErr)
	}
}()
for reservation, err := range client.Reservations().ListAll(context.Background(), nil) {
	if err != nil {
		log.Print(err)
		return
	}
	fmt.Println(reservation.ID, reservation.RawStatus)
}
```

#### Reservations.Renew [#reservationsrenew]

```go
func (s *Reservations) Renew(ctx context.Context, id string, opts *RenewReservationOptions) (*MacReservation, error)
```

Renew pays for the reservation's next period. Reuse an explicit idempotency
key with identical input after a lost response to avoid paying twice.
ErrLimitExceeded reports the organization's reservation limit.

**Example**:

```go
client, err := daytona.New()
if err != nil {
	log.Print(err)
	return
}
defer func() {
	if closeErr := client.Close(); closeErr != nil {
		log.Print(closeErr)
	}
}()
// This pays for another period. Keep the key stable if retrying this renewal.
reservation, err := client.Reservations().Renew(
	context.Background(), "reservation-id", &daytona.RenewReservationOptions{
		IdempotencyKey: "my-next-period",
	},
)
if err != nil {
	log.Print(err)
	return
}
fmt.Println(reservation.PeriodN, reservation.PeriodEnd)
```

#### Reservations.Update [#reservationsupdate]

```go
func (s *Reservations) Update(ctx context.Context, id string, autoRenew bool) (*MacReservation, error)
```

Update enables or disables automatic renewal. Disabling it does not require
macOS access. A reservation that is no longer live returns ErrConflict.

**Example**:

```go
client, err := daytona.New()
if err != nil {
	log.Print(err)
	return
}
defer func() {
	if closeErr := client.Close(); closeErr != nil {
		log.Print(closeErr)
	}
}()
// Stop future automatic renewals; this does not refund the current period.
reservation, err := client.Reservations().Update(context.Background(), "reservation-id", false)
if err != nil {
	log.Print(err)
	return
}
fmt.Println(reservation.AutoRenew, reservation.PeriodEnd)
```

## CreateReservationOptions [#createreservationoptions]

```go
type CreateReservationOptions struct {
	// Model is a registered model slug; empty selects the region's default.
	// An unavailable model is never upgraded.
	Model string
	// AutoRenew overrides the organization's setting; nil uses that setting.
	AutoRenew *bool
	// IdempotencyKey is reused on retries to avoid buying a second Mac.
	// Empty generates a fresh key for this call.
	IdempotencyKey string
}
```

CreateReservationOptions controls an optional model, renewal policy and retry key.

## CreateReservationsBulkOptions [#createreservationsbulkoptions]

```go
type CreateReservationsBulkOptions struct {
	// Model is a registered model slug; empty selects the region's default.
	Model string
	// AutoRenew overrides the organization's setting; nil uses that setting.
	AutoRenew *bool
	// IdempotencyKey avoids another purchase on retry; empty generates a key.
	IdempotencyKey string
	// MinCount is the fewest Macs to accept, from 1 to count; zero requires count.
	MinCount int
}
```

CreateReservationsBulkOptions controls a bulk reservation purchase.

## ListReservationsOptions [#listreservationsoptions]

```go
type ListReservationsOptions struct {
	// Cursor is the opaque continuation cursor.
	Cursor string
	// Limit is 1–200; zero uses the server default.
	Limit int
}
```

ListReservationsOptions selects one page of reservations.

## MacReservation [#macreservation]

```go
type MacReservation struct {
	// ID identifies the reservation.
	ID string
	// OrgID identifies the owning organization.
	OrgID string
	// ProjectID identifies the owning project.
	ProjectID string
	// Region is the reservation's region.
	Region string
	// AutoRenew reports whether the reservation renews automatically.
	AutoRenew bool
	// SlotsUsed counts occupied sandbox slots.
	SlotsUsed int64
	// Model is the model slug, or empty when unreported.
	Model string
	// Capacity is nil when physical capacity is unreported.
	Capacity *MacResources
	// ResourcesUsed is the current resource usage.
	ResourcesUsed MacResources
	// PeriodN is the server's billing-period number.
	PeriodN int64
	// Period is the billing-period duration.
	Period time.Duration
	// CreatedAt is the creation timestamp.
	CreatedAt time.Time
	// ActivatedAt is the activation timestamp.
	ActivatedAt time.Time
	// PendingMacStartedAt is when Mac assignment began.
	PendingMacStartedAt time.Time
	// PeriodStartedAt is when the current period began.
	PeriodStartedAt time.Time
	// PeriodEnd is when the current period ends.
	PeriodEnd time.Time
	// ReissuedAt is the latest reissue timestamp.
	ReissuedAt time.Time
	// EndedAt is when the reservation ended.
	EndedAt time.Time
	// RenewalPending reports a pending renewal.
	RenewalPending bool
	// RenewalError is the server's renewal error, if any.
	RenewalError string
	// Status is the normalized reservation state.
	Status MacReservationStatus
	// RawStatus preserves the server state verbatim.
	RawStatus string
	// EndReason is empty when absent, otherwise normalized.
	EndReason MacReservationEndReason
	// RawEndReason preserves the server end reason verbatim.
	RawEndReason string
	// Origin is the normalized purchase origin.
	Origin MacReservationOrigin
	// RawOrigin preserves the server origin verbatim.
	RawOrigin string
}
```

MacReservation is a caller-owned observation of a dedicated-Mac reservation.
Optional timestamps are zero when absent. Reservations are billed per period.

## MacReservationBatch [#macreservationbatch]

```go
type MacReservationBatch struct {
	// Requested is the number requested.
	Requested int64
	// Reserved is the number purchased.
	Reserved int64
	// Reservations contains the purchased reservations.
	Reservations []MacReservation
}
```

MacReservationBatch contains the results of a single bulk purchase.

## MacReservationEndReason [#macreservationendreason]

```go
type MacReservationEndReason string
```

MacReservationEndReason describes why a reservation ended; empty means absent.

```go
const (
	// MacReservationEndReasonUnknown indicates an unrecognized RawEndReason.
	MacReservationEndReasonUnknown MacReservationEndReason = "unknown"
	// MacReservationEndReasonExpired means the period expired.
	MacReservationEndReasonExpired MacReservationEndReason = "expired"
	// MacReservationEndReasonReleased means the reservation was released.
	MacReservationEndReasonReleased MacReservationEndReason = "released"
	// MacReservationEndReasonChargeFailed means payment failed.
	MacReservationEndReasonChargeFailed MacReservationEndReason = "charge_failed"
	// MacReservationEndReasonNotAccepted means the reservation was not accepted.
	MacReservationEndReasonNotAccepted MacReservationEndReason = "not_accepted"
	// MacReservationEndReasonReissued means the reservation was reissued.
	MacReservationEndReasonReissued MacReservationEndReason = "reissued"
	// MacReservationEndReasonOperator means an operator ended the reservation.
	MacReservationEndReasonOperator MacReservationEndReason = "operator"
)
```

## MacReservationOrigin [#macreservationorigin]

```go
type MacReservationOrigin string
```

MacReservationOrigin describes how a reservation was purchased.

```go
const (
	// MacReservationOriginUnknown indicates an unrecognized RawOrigin.
	MacReservationOriginUnknown MacReservationOrigin = "unknown"
	// MacReservationOriginExplicit means the reservation was explicitly purchased.
	MacReservationOriginExplicit MacReservationOrigin = "explicit"
	// MacReservationOriginAuto means auto-reserve purchased the reservation.
	MacReservationOriginAuto MacReservationOrigin = "auto"
)
```

## MacReservationStatus [#macreservationstatus]

```go
type MacReservationStatus string
```

MacReservationStatus is an observed reservation state.

```go
const (
	// MacReservationStatusUnknown indicates an unrecognized RawStatus.
	MacReservationStatusUnknown MacReservationStatus = "unknown"
	// MacReservationStatusPendingCharge means payment is pending.
	MacReservationStatusPendingCharge MacReservationStatus = "pending_charge"
	// MacReservationStatusPendingMac means a Mac is being assigned.
	MacReservationStatusPendingMac MacReservationStatus = "pending_mac"
	// MacReservationStatusActive means the reservation is active.
	MacReservationStatusActive MacReservationStatus = "active"
	// MacReservationStatusEnding means the reservation is ending.
	MacReservationStatusEnding MacReservationStatus = "ending"
	// MacReservationStatusReleased means the Mac has been released.
	MacReservationStatusReleased MacReservationStatus = "released"
	// MacReservationStatusFailed means the reservation failed.
	MacReservationStatusFailed MacReservationStatus = "failed"
)
```

## RenewReservationOptions [#renewreservationoptions]

```go
type RenewReservationOptions struct {
	// IdempotencyKey avoids paying for another period on retry.
	// Empty generates a fresh key for this call.
	IdempotencyKey string
}
```

RenewReservationOptions controls safe retries of a billed renewal.
