github.com/anthropics/anthropic-sdk-go@v1.70.1/betadream.go (about) 1 // File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. 2 3 package anthropic 4 5 import ( 6 "context" 7 "encoding/json" 8 "errors" 9 "fmt" 10 "net/http" 11 "net/url" 12 "slices" 13 "time" 14 15 "github.com/anthropics/anthropic-sdk-go/internal/apijson" 16 "github.com/anthropics/anthropic-sdk-go/internal/apiquery" 17 "github.com/anthropics/anthropic-sdk-go/internal/requestconfig" 18 "github.com/anthropics/anthropic-sdk-go/option" 19 "github.com/anthropics/anthropic-sdk-go/packages/pagination" 20 "github.com/anthropics/anthropic-sdk-go/packages/param" 21 "github.com/anthropics/anthropic-sdk-go/packages/respjson" 22 ) 23 24 // BetaDreamService contains methods and other services that help with interacting 25 // with the anthropic API. 26 // 27 // Note, unlike clients, this service does not read variables from the environment 28 // automatically. You should not instantiate this service directly, and instead use 29 // the [NewBetaDreamService] method instead. 30 type BetaDreamService struct { 31 Options []option.RequestOption 32 } 33 34 // NewBetaDreamService generates a new service that applies the given options to 35 // each request. These options are applied after the parent client's options (if 36 // there is one), and before any request-specific options. 37 func NewBetaDreamService(opts ...option.RequestOption) (r BetaDreamService) { 38 r = BetaDreamService{} 39 r.Options = opts 40 return 41 } 42 43 // Create a Dream 44 func (r *BetaDreamService) New(ctx context.Context, params BetaDreamNewParams, opts ...option.RequestOption) (res *BetaDream, err error) { 45 for _, v := range params.Betas { 46 opts = append(opts, option.WithHeaderAdd("anthropic-beta", fmt.Sprintf("%v", v))) 47 } 48 if !param.IsOmitted(params.WorkspaceID) { 49 opts = append(opts, option.WithHeader("anthropic-workspace-id", fmt.Sprintf("%v", params.WorkspaceID.Value))) 50 } 51 opts = slices.Concat(r.Options, opts) 52 opts = append([]option.RequestOption{option.WithHeader("anthropic-beta", "dreaming-2026-04-21")}, opts...) 53 path := "v1/dreams?beta=true" 54 err = requestconfig.ExecuteNewRequest(ctx, http.MethodPost, path, params, &res, opts...) 55 return res, err 56 } 57 58 // Get a Dream 59 func (r *BetaDreamService) Get(ctx context.Context, dreamID string, query BetaDreamGetParams, opts ...option.RequestOption) (res *BetaDream, err error) { 60 for _, v := range query.Betas { 61 opts = append(opts, option.WithHeaderAdd("anthropic-beta", fmt.Sprintf("%v", v))) 62 } 63 if !param.IsOmitted(query.WorkspaceID) { 64 opts = append(opts, option.WithHeader("anthropic-workspace-id", fmt.Sprintf("%v", query.WorkspaceID.Value))) 65 } 66 opts = slices.Concat(r.Options, opts) 67 opts = append([]option.RequestOption{option.WithHeader("anthropic-beta", "dreaming-2026-04-21")}, opts...) 68 if dreamID == "" { 69 err = errors.New("missing required dream_id parameter") 70 return nil, err 71 } 72 path := fmt.Sprintf("v1/dreams/%s?beta=true", dreamID) 73 err = requestconfig.ExecuteNewRequest(ctx, http.MethodGet, path, nil, &res, opts...) 74 return res, err 75 } 76 77 // List Dreams 78 func (r *BetaDreamService) List(ctx context.Context, params BetaDreamListParams, opts ...option.RequestOption) (res *pagination.PageCursor[BetaDream], err error) { 79 var raw *http.Response 80 for _, v := range params.Betas { 81 opts = append(opts, option.WithHeaderAdd("anthropic-beta", fmt.Sprintf("%v", v))) 82 } 83 if !param.IsOmitted(params.WorkspaceID) { 84 opts = append(opts, option.WithHeader("anthropic-workspace-id", fmt.Sprintf("%v", params.WorkspaceID.Value))) 85 } 86 opts = slices.Concat(r.Options, opts) 87 opts = append([]option.RequestOption{option.WithHeader("anthropic-beta", "dreaming-2026-04-21"), option.WithResponseInto(&raw)}, opts...) 88 path := "v1/dreams?beta=true" 89 cfg, err := requestconfig.NewRequestConfig(ctx, http.MethodGet, path, params, &res, opts...) 90 if err != nil { 91 return nil, err 92 } 93 err = cfg.Execute() 94 if err != nil { 95 return nil, err 96 } 97 res.SetPageConfig(cfg, raw) 98 return res, nil 99 } 100 101 // List Dreams 102 func (r *BetaDreamService) ListAutoPaging(ctx context.Context, params BetaDreamListParams, opts ...option.RequestOption) *pagination.PageCursorAutoPager[BetaDream] { 103 return pagination.NewPageCursorAutoPager(r.List(ctx, params, opts...)) 104 } 105 106 // Archive a Dream 107 func (r *BetaDreamService) Archive(ctx context.Context, dreamID string, body BetaDreamArchiveParams, opts ...option.RequestOption) (res *BetaDream, err error) { 108 for _, v := range body.Betas { 109 opts = append(opts, option.WithHeaderAdd("anthropic-beta", fmt.Sprintf("%v", v))) 110 } 111 if !param.IsOmitted(body.WorkspaceID) { 112 opts = append(opts, option.WithHeader("anthropic-workspace-id", fmt.Sprintf("%v", body.WorkspaceID.Value))) 113 } 114 opts = slices.Concat(r.Options, opts) 115 opts = append([]option.RequestOption{option.WithHeader("anthropic-beta", "dreaming-2026-04-21")}, opts...) 116 if dreamID == "" { 117 err = errors.New("missing required dream_id parameter") 118 return nil, err 119 } 120 path := fmt.Sprintf("v1/dreams/%s/archive?beta=true", dreamID) 121 err = requestconfig.ExecuteNewRequest(ctx, http.MethodPost, path, nil, &res, opts...) 122 return res, err 123 } 124 125 // Cancel a Dream 126 func (r *BetaDreamService) Cancel(ctx context.Context, dreamID string, body BetaDreamCancelParams, opts ...option.RequestOption) (res *BetaDream, err error) { 127 for _, v := range body.Betas { 128 opts = append(opts, option.WithHeaderAdd("anthropic-beta", fmt.Sprintf("%v", v))) 129 } 130 if !param.IsOmitted(body.WorkspaceID) { 131 opts = append(opts, option.WithHeader("anthropic-workspace-id", fmt.Sprintf("%v", body.WorkspaceID.Value))) 132 } 133 opts = slices.Concat(r.Options, opts) 134 opts = append([]option.RequestOption{option.WithHeader("anthropic-beta", "dreaming-2026-04-21")}, opts...) 135 if dreamID == "" { 136 err = errors.New("missing required dream_id parameter") 137 return nil, err 138 } 139 path := fmt.Sprintf("v1/dreams/%s/cancel?beta=true", dreamID) 140 err = requestconfig.ExecuteNewRequest(ctx, http.MethodPost, path, nil, &res, opts...) 141 return res, err 142 } 143 144 // An asynchronous memory-consolidation job that reads a memory store plus a set of 145 // session transcripts and writes consolidated memories into an output memory store 146 // — a new store by default, or an existing store chosen via output_behavior. The 147 // Dreams API is in research preview: the request and response shapes are volatile 148 // and may change without the deprecation period that applies to 149 // generally-available endpoints. 150 type BetaDream struct { 151 ID string `json:"id" api:"required"` 152 // A timestamp in RFC 3339 format 153 ArchivedAt time.Time `json:"archived_at" api:"required" format:"date-time"` 154 // A timestamp in RFC 3339 format 155 CreatedAt time.Time `json:"created_at" api:"required" format:"date-time"` 156 // A timestamp in RFC 3339 format 157 EndedAt time.Time `json:"ended_at" api:"required" format:"date-time"` 158 // Failure detail for a Dream whose `status` is `failed`. 159 Error BetaDreamError `json:"error" api:"required"` 160 Inputs []BetaDreamInputUnion `json:"inputs" api:"required"` 161 Instructions string `json:"instructions" api:"required"` 162 // Model identifier and configuration applied to every pipeline stage. Same wire 163 // shape as the Agents API ModelConfig. 164 Model BetaDreamModelConfig `json:"model" api:"required"` 165 // The default destination: the job creates a new output memory store as a clone of 166 // the memory_store input and writes the consolidated memories into it. The input 167 // store is never mutated. 168 OutputBehavior BetaOutputBehaviorUnion `json:"output_behavior" api:"required"` 169 Outputs []BetaDreamOutput `json:"outputs" api:"required"` 170 SessionID string `json:"session_id" api:"required"` 171 // Lifecycle status of a Dream. 172 // 173 // Any of "pending", "running", "completed", "failed", "canceled". 174 Status BetaDreamStatus `json:"status" api:"required"` 175 // Any of "dream". 176 Type BetaDreamType `json:"type" api:"required"` 177 // Cumulative token usage for the dream across every pipeline stage. 178 Usage BetaDreamUsage `json:"usage" api:"required"` 179 // JSON contains metadata for fields, check presence with [respjson.Field.Valid]. 180 JSON struct { 181 ID respjson.Field 182 ArchivedAt respjson.Field 183 CreatedAt respjson.Field 184 EndedAt respjson.Field 185 Error respjson.Field 186 Inputs respjson.Field 187 Instructions respjson.Field 188 Model respjson.Field 189 OutputBehavior respjson.Field 190 Outputs respjson.Field 191 SessionID respjson.Field 192 Status respjson.Field 193 Type respjson.Field 194 Usage respjson.Field 195 ExtraFields map[string]respjson.Field 196 raw string 197 } `json:"-"` 198 } 199 200 // Returns the unmodified JSON received from the API 201 func (r BetaDream) RawJSON() string { return r.JSON.raw } 202 func (r *BetaDream) UnmarshalJSON(data []byte) error { 203 return apijson.UnmarshalRoot(data, r) 204 } 205 206 type BetaDreamType string 207 208 const ( 209 BetaDreamTypeDream BetaDreamType = "dream" 210 ) 211 212 // Failure detail for a Dream whose `status` is `failed`. 213 type BetaDreamError struct { 214 Message string `json:"message" api:"required"` 215 Type string `json:"type" api:"required"` 216 // JSON contains metadata for fields, check presence with [respjson.Field.Valid]. 217 JSON struct { 218 Message respjson.Field 219 Type respjson.Field 220 ExtraFields map[string]respjson.Field 221 raw string 222 } `json:"-"` 223 } 224 225 // Returns the unmodified JSON received from the API 226 func (r BetaDreamError) RawJSON() string { return r.JSON.raw } 227 func (r *BetaDreamError) UnmarshalJSON(data []byte) error { 228 return apijson.UnmarshalRoot(data, r) 229 } 230 231 // BetaDreamInputUnion contains all possible properties and values from 232 // [BetaDreamMemoryStoreInput], [BetaDreamSessionsInput]. 233 // 234 // Use the [BetaDreamInputUnion.AsAny] method to switch on the variant. 235 // 236 // Use the methods beginning with 'As' to cast the union to one of its variants. 237 type BetaDreamInputUnion struct { 238 // This field is from variant [BetaDreamMemoryStoreInput]. 239 MemoryStoreID string `json:"memory_store_id"` 240 // Any of "memory_store", "sessions". 241 Type string `json:"type"` 242 // This field is from variant [BetaDreamSessionsInput]. 243 SessionIDs []string `json:"session_ids"` 244 JSON struct { 245 MemoryStoreID respjson.Field 246 Type respjson.Field 247 SessionIDs respjson.Field 248 raw string 249 } `json:"-"` 250 } 251 252 // anyBetaDreamInput is implemented by each variant of [BetaDreamInputUnion] to add 253 // type safety for the return type of [BetaDreamInputUnion.AsAny] 254 type anyBetaDreamInput interface { 255 implBetaDreamInputUnion() 256 } 257 258 func (BetaDreamMemoryStoreInput) implBetaDreamInputUnion() {} 259 func (BetaDreamSessionsInput) implBetaDreamInputUnion() {} 260 261 // Use the following switch statement to find the correct variant 262 // 263 // switch variant := BetaDreamInputUnion.AsAny().(type) { 264 // case anthropic.BetaDreamMemoryStoreInput: 265 // case anthropic.BetaDreamSessionsInput: 266 // default: 267 // fmt.Errorf("no variant present") 268 // } 269 func (u BetaDreamInputUnion) AsAny() anyBetaDreamInput { 270 switch u.Type { 271 case "memory_store": 272 return u.AsMemoryStore() 273 case "sessions": 274 return u.AsSessions() 275 } 276 return nil 277 } 278 279 func (u BetaDreamInputUnion) AsMemoryStore() (v BetaDreamMemoryStoreInput) { 280 apijson.UnmarshalRoot(json.RawMessage(u.JSON.raw), &v) 281 return 282 } 283 284 func (u BetaDreamInputUnion) AsSessions() (v BetaDreamSessionsInput) { 285 apijson.UnmarshalRoot(json.RawMessage(u.JSON.raw), &v) 286 return 287 } 288 289 // Returns the unmodified JSON received from the API 290 func (u BetaDreamInputUnion) RawJSON() string { return u.JSON.raw } 291 292 func (r *BetaDreamInputUnion) UnmarshalJSON(data []byte) error { 293 return apijson.UnmarshalRoot(data, r) 294 } 295 296 // ToParam converts this BetaDreamInputUnion to a BetaDreamInputUnionParam. 297 // 298 // Warning: the fields of the param type will not be present. ToParam should only 299 // be used at the last possible moment before sending a request. Test for this with 300 // BetaDreamInputUnionParam.Overrides() 301 func (r BetaDreamInputUnion) ToParam() BetaDreamInputUnionParam { 302 return param.Override[BetaDreamInputUnionParam](json.RawMessage(r.RawJSON())) 303 } 304 305 func BetaDreamInputParamOfMemoryStore(memoryStoreID string) BetaDreamInputUnionParam { 306 var memoryStore BetaDreamMemoryStoreInputParam 307 memoryStore.MemoryStoreID = memoryStoreID 308 return BetaDreamInputUnionParam{OfMemoryStore: &memoryStore} 309 } 310 311 func BetaDreamInputParamOfSessions(sessionIDs []string) BetaDreamInputUnionParam { 312 var sessions BetaDreamSessionsInputParam 313 sessions.SessionIDs = sessionIDs 314 return BetaDreamInputUnionParam{OfSessions: &sessions} 315 } 316 317 // Only one field can be non-zero. 318 // 319 // Use [param.IsOmitted] to confirm if a field is set. 320 type BetaDreamInputUnionParam struct { 321 OfMemoryStore *BetaDreamMemoryStoreInputParam `json:",omitzero,inline"` 322 OfSessions *BetaDreamSessionsInputParam `json:",omitzero,inline"` 323 paramUnion 324 } 325 326 func (u BetaDreamInputUnionParam) MarshalJSON() ([]byte, error) { 327 return param.MarshalUnion(u, u.OfMemoryStore, u.OfSessions) 328 } 329 func (u *BetaDreamInputUnionParam) UnmarshalJSON(data []byte) error { 330 return apijson.UnmarshalRoot(data, u) 331 } 332 333 func (u *BetaDreamInputUnionParam) asAny() any { 334 if !param.IsOmitted(u.OfMemoryStore) { 335 return u.OfMemoryStore 336 } else if !param.IsOmitted(u.OfSessions) { 337 return u.OfSessions 338 } 339 return nil 340 } 341 342 // Returns a pointer to the underlying variant's property, if present. 343 func (u BetaDreamInputUnionParam) GetMemoryStoreID() *string { 344 if vt := u.OfMemoryStore; vt != nil { 345 return &vt.MemoryStoreID 346 } 347 return nil 348 } 349 350 // Returns a pointer to the underlying variant's property, if present. 351 func (u BetaDreamInputUnionParam) GetSessionIDs() []string { 352 if vt := u.OfSessions; vt != nil { 353 return vt.SessionIDs 354 } 355 return nil 356 } 357 358 // Returns a pointer to the underlying variant's property, if present. 359 func (u BetaDreamInputUnionParam) GetType() *string { 360 if vt := u.OfMemoryStore; vt != nil { 361 return (*string)(&vt.Type) 362 } else if vt := u.OfSessions; vt != nil { 363 return (*string)(&vt.Type) 364 } 365 return nil 366 } 367 368 func init() { 369 apijson.RegisterUnion[BetaDreamInputUnionParam]( 370 "type", 371 apijson.Discriminator[BetaDreamMemoryStoreInputParam]("memory_store"), 372 apijson.Discriminator[BetaDreamSessionsInputParam]("sessions"), 373 ) 374 } 375 376 // An input memory store the dream reads from. The dream never mutates this store 377 // unless it is also the destination: with output_behavior {type: 378 // "update_existing"} the job consolidates this store in place. 379 type BetaDreamMemoryStoreInput struct { 380 MemoryStoreID string `json:"memory_store_id" api:"required"` 381 // Any of "memory_store". 382 Type BetaDreamMemoryStoreInputType `json:"type" api:"required"` 383 // JSON contains metadata for fields, check presence with [respjson.Field.Valid]. 384 JSON struct { 385 MemoryStoreID respjson.Field 386 Type respjson.Field 387 ExtraFields map[string]respjson.Field 388 raw string 389 } `json:"-"` 390 } 391 392 // Returns the unmodified JSON received from the API 393 func (r BetaDreamMemoryStoreInput) RawJSON() string { return r.JSON.raw } 394 func (r *BetaDreamMemoryStoreInput) UnmarshalJSON(data []byte) error { 395 return apijson.UnmarshalRoot(data, r) 396 } 397 398 // ToParam converts this BetaDreamMemoryStoreInput to a 399 // BetaDreamMemoryStoreInputParam. 400 // 401 // Warning: the fields of the param type will not be present. ToParam should only 402 // be used at the last possible moment before sending a request. Test for this with 403 // BetaDreamMemoryStoreInputParam.Overrides() 404 func (r BetaDreamMemoryStoreInput) ToParam() BetaDreamMemoryStoreInputParam { 405 return param.Override[BetaDreamMemoryStoreInputParam](json.RawMessage(r.RawJSON())) 406 } 407 408 type BetaDreamMemoryStoreInputType string 409 410 const ( 411 BetaDreamMemoryStoreInputTypeMemoryStore BetaDreamMemoryStoreInputType = "memory_store" 412 ) 413 414 // An input memory store the dream reads from. The dream never mutates this store 415 // unless it is also the destination: with output_behavior {type: 416 // "update_existing"} the job consolidates this store in place. 417 // 418 // The properties MemoryStoreID, Type are required. 419 type BetaDreamMemoryStoreInputParam struct { 420 MemoryStoreID string `json:"memory_store_id" api:"required"` 421 // Any of "memory_store". 422 Type BetaDreamMemoryStoreInputType `json:"type,omitzero" api:"required"` 423 paramObj 424 } 425 426 func (r BetaDreamMemoryStoreInputParam) MarshalJSON() (data []byte, err error) { 427 type shadow BetaDreamMemoryStoreInputParam 428 return param.MarshalObject(r, (*shadow)(&r)) 429 } 430 func (r *BetaDreamMemoryStoreInputParam) UnmarshalJSON(data []byte) error { 431 return apijson.UnmarshalRoot(data, r) 432 } 433 434 // Model identifier and configuration applied to every pipeline stage. Same wire 435 // shape as the Agents API ModelConfig. 436 type BetaDreamModelConfig struct { 437 // Model identifier, e.g. "claude-opus-5". 1-256 characters. 438 ID string `json:"id" api:"required"` 439 // Inference speed mode. `fast` provides significantly faster output token 440 // generation at premium pricing. Not all models support `fast`; invalid 441 // combinations are rejected at create time. 442 // 443 // Any of "standard", "fast". 444 Speed BetaDreamModelConfigSpeed `json:"speed"` 445 // JSON contains metadata for fields, check presence with [respjson.Field.Valid]. 446 JSON struct { 447 ID respjson.Field 448 Speed respjson.Field 449 ExtraFields map[string]respjson.Field 450 raw string 451 } `json:"-"` 452 } 453 454 // Returns the unmodified JSON received from the API 455 func (r BetaDreamModelConfig) RawJSON() string { return r.JSON.raw } 456 func (r *BetaDreamModelConfig) UnmarshalJSON(data []byte) error { 457 return apijson.UnmarshalRoot(data, r) 458 } 459 460 // Inference speed mode. `fast` provides significantly faster output token 461 // generation at premium pricing. Not all models support `fast`; invalid 462 // combinations are rejected at create time. 463 type BetaDreamModelConfigSpeed string 464 465 const ( 466 BetaDreamModelConfigSpeedStandard BetaDreamModelConfigSpeed = "standard" 467 BetaDreamModelConfigSpeedFast BetaDreamModelConfigSpeed = "fast" 468 ) 469 470 // Model identifier and configuration applied to every pipeline stage. 471 // 472 // The property ID is required. 473 type BetaDreamModelConfigParam struct { 474 // Model identifier, e.g. "claude-opus-5". 1-256 characters. 475 ID string `json:"id" api:"required"` 476 // Inference speed mode. `fast` provides significantly faster output token 477 // generation at premium pricing. Not all models support `fast`; invalid 478 // combinations are rejected at create time. 479 // 480 // Any of "standard", "fast". 481 Speed BetaDreamModelConfigParamSpeed `json:"speed,omitzero"` 482 paramObj 483 } 484 485 func (r BetaDreamModelConfigParam) MarshalJSON() (data []byte, err error) { 486 type shadow BetaDreamModelConfigParam 487 return param.MarshalObject(r, (*shadow)(&r)) 488 } 489 func (r *BetaDreamModelConfigParam) UnmarshalJSON(data []byte) error { 490 return apijson.UnmarshalRoot(data, r) 491 } 492 493 // Inference speed mode. `fast` provides significantly faster output token 494 // generation at premium pricing. Not all models support `fast`; invalid 495 // combinations are rejected at create time. 496 type BetaDreamModelConfigParamSpeed string 497 498 const ( 499 BetaDreamModelConfigParamSpeedStandard BetaDreamModelConfigParamSpeed = "standard" 500 BetaDreamModelConfigParamSpeedFast BetaDreamModelConfigParamSpeed = "fast" 501 ) 502 503 // An output memory store the dream writes consolidated memories into. 504 type BetaDreamOutput struct { 505 MemoryStoreID string `json:"memory_store_id" api:"required"` 506 // Any of "memory_store". 507 Type BetaDreamOutputType `json:"type" api:"required"` 508 // JSON contains metadata for fields, check presence with [respjson.Field.Valid]. 509 JSON struct { 510 MemoryStoreID respjson.Field 511 Type respjson.Field 512 ExtraFields map[string]respjson.Field 513 raw string 514 } `json:"-"` 515 } 516 517 // Returns the unmodified JSON received from the API 518 func (r BetaDreamOutput) RawJSON() string { return r.JSON.raw } 519 func (r *BetaDreamOutput) UnmarshalJSON(data []byte) error { 520 return apijson.UnmarshalRoot(data, r) 521 } 522 523 type BetaDreamOutputType string 524 525 const ( 526 BetaDreamOutputTypeMemoryStore BetaDreamOutputType = "memory_store" 527 ) 528 529 // Input session transcripts the dream reads. 530 type BetaDreamSessionsInput struct { 531 SessionIDs []string `json:"session_ids" api:"required"` 532 // Any of "sessions". 533 Type BetaDreamSessionsInputType `json:"type" api:"required"` 534 // JSON contains metadata for fields, check presence with [respjson.Field.Valid]. 535 JSON struct { 536 SessionIDs respjson.Field 537 Type respjson.Field 538 ExtraFields map[string]respjson.Field 539 raw string 540 } `json:"-"` 541 } 542 543 // Returns the unmodified JSON received from the API 544 func (r BetaDreamSessionsInput) RawJSON() string { return r.JSON.raw } 545 func (r *BetaDreamSessionsInput) UnmarshalJSON(data []byte) error { 546 return apijson.UnmarshalRoot(data, r) 547 } 548 549 // ToParam converts this BetaDreamSessionsInput to a BetaDreamSessionsInputParam. 550 // 551 // Warning: the fields of the param type will not be present. ToParam should only 552 // be used at the last possible moment before sending a request. Test for this with 553 // BetaDreamSessionsInputParam.Overrides() 554 func (r BetaDreamSessionsInput) ToParam() BetaDreamSessionsInputParam { 555 return param.Override[BetaDreamSessionsInputParam](json.RawMessage(r.RawJSON())) 556 } 557 558 type BetaDreamSessionsInputType string 559 560 const ( 561 BetaDreamSessionsInputTypeSessions BetaDreamSessionsInputType = "sessions" 562 ) 563 564 // Input session transcripts the dream reads. 565 // 566 // The properties SessionIDs, Type are required. 567 type BetaDreamSessionsInputParam struct { 568 SessionIDs []string `json:"session_ids,omitzero" api:"required"` 569 // Any of "sessions". 570 Type BetaDreamSessionsInputType `json:"type,omitzero" api:"required"` 571 paramObj 572 } 573 574 func (r BetaDreamSessionsInputParam) MarshalJSON() (data []byte, err error) { 575 type shadow BetaDreamSessionsInputParam 576 return param.MarshalObject(r, (*shadow)(&r)) 577 } 578 func (r *BetaDreamSessionsInputParam) UnmarshalJSON(data []byte) error { 579 return apijson.UnmarshalRoot(data, r) 580 } 581 582 // Lifecycle status of a Dream. 583 type BetaDreamStatus string 584 585 const ( 586 BetaDreamStatusPending BetaDreamStatus = "pending" 587 BetaDreamStatusRunning BetaDreamStatus = "running" 588 BetaDreamStatusCompleted BetaDreamStatus = "completed" 589 BetaDreamStatusFailed BetaDreamStatus = "failed" 590 BetaDreamStatusCanceled BetaDreamStatus = "canceled" 591 ) 592 593 // Cumulative token usage for the dream across every pipeline stage. 594 type BetaDreamUsage struct { 595 // Total tokens used to create prompt-cache entries (sum of all TTL tiers). 596 CacheCreationInputTokens int64 `json:"cache_creation_input_tokens" api:"required"` 597 // Total tokens read from prompt cache. 598 CacheReadInputTokens int64 `json:"cache_read_input_tokens" api:"required"` 599 // Total uncached input tokens consumed across every pipeline stage. 600 InputTokens int64 `json:"input_tokens" api:"required"` 601 // Total output tokens generated across every pipeline stage. 602 OutputTokens int64 `json:"output_tokens" api:"required"` 603 // JSON contains metadata for fields, check presence with [respjson.Field.Valid]. 604 JSON struct { 605 CacheCreationInputTokens respjson.Field 606 CacheReadInputTokens respjson.Field 607 InputTokens respjson.Field 608 OutputTokens respjson.Field 609 ExtraFields map[string]respjson.Field 610 raw string 611 } `json:"-"` 612 } 613 614 // Returns the unmodified JSON received from the API 615 func (r BetaDreamUsage) RawJSON() string { return r.JSON.raw } 616 func (r *BetaDreamUsage) UnmarshalJSON(data []byte) error { 617 return apijson.UnmarshalRoot(data, r) 618 } 619 620 // BetaOutputBehaviorUnion contains all possible properties and values from 621 // [BetaOutputBehaviorCreateNew], [BetaOutputBehaviorUpdateExisting]. 622 // 623 // Use the [BetaOutputBehaviorUnion.AsAny] method to switch on the variant. 624 // 625 // Use the methods beginning with 'As' to cast the union to one of its variants. 626 type BetaOutputBehaviorUnion struct { 627 // Any of "create_new", "update_existing". 628 Type string `json:"type"` 629 // This field is from variant [BetaOutputBehaviorUpdateExisting]. 630 MemoryStoreID string `json:"memory_store_id"` 631 JSON struct { 632 Type respjson.Field 633 MemoryStoreID respjson.Field 634 raw string 635 } `json:"-"` 636 } 637 638 // anyBetaOutputBehavior is implemented by each variant of 639 // [BetaOutputBehaviorUnion] to add type safety for the return type of 640 // [BetaOutputBehaviorUnion.AsAny] 641 type anyBetaOutputBehavior interface { 642 implBetaOutputBehaviorUnion() 643 } 644 645 func (BetaOutputBehaviorCreateNew) implBetaOutputBehaviorUnion() {} 646 func (BetaOutputBehaviorUpdateExisting) implBetaOutputBehaviorUnion() {} 647 648 // Use the following switch statement to find the correct variant 649 // 650 // switch variant := BetaOutputBehaviorUnion.AsAny().(type) { 651 // case anthropic.BetaOutputBehaviorCreateNew: 652 // case anthropic.BetaOutputBehaviorUpdateExisting: 653 // default: 654 // fmt.Errorf("no variant present") 655 // } 656 func (u BetaOutputBehaviorUnion) AsAny() anyBetaOutputBehavior { 657 switch u.Type { 658 case "create_new": 659 return u.AsCreateNew() 660 case "update_existing": 661 return u.AsUpdateExisting() 662 } 663 return nil 664 } 665 666 func (u BetaOutputBehaviorUnion) AsCreateNew() (v BetaOutputBehaviorCreateNew) { 667 apijson.UnmarshalRoot(json.RawMessage(u.JSON.raw), &v) 668 return 669 } 670 671 func (u BetaOutputBehaviorUnion) AsUpdateExisting() (v BetaOutputBehaviorUpdateExisting) { 672 apijson.UnmarshalRoot(json.RawMessage(u.JSON.raw), &v) 673 return 674 } 675 676 // Returns the unmodified JSON received from the API 677 func (u BetaOutputBehaviorUnion) RawJSON() string { return u.JSON.raw } 678 679 func (r *BetaOutputBehaviorUnion) UnmarshalJSON(data []byte) error { 680 return apijson.UnmarshalRoot(data, r) 681 } 682 683 // ToParam converts this BetaOutputBehaviorUnion to a BetaOutputBehaviorUnionParam. 684 // 685 // Warning: the fields of the param type will not be present. ToParam should only 686 // be used at the last possible moment before sending a request. Test for this with 687 // BetaOutputBehaviorUnionParam.Overrides() 688 func (r BetaOutputBehaviorUnion) ToParam() BetaOutputBehaviorUnionParam { 689 return param.Override[BetaOutputBehaviorUnionParam](json.RawMessage(r.RawJSON())) 690 } 691 692 func BetaOutputBehaviorParamOfCreateNew(type_ BetaOutputBehaviorCreateNewType) BetaOutputBehaviorUnionParam { 693 var createNew BetaOutputBehaviorCreateNewParam 694 createNew.Type = type_ 695 return BetaOutputBehaviorUnionParam{OfCreateNew: &createNew} 696 } 697 698 func BetaOutputBehaviorParamOfUpdateExisting(memoryStoreID string) BetaOutputBehaviorUnionParam { 699 var updateExisting BetaOutputBehaviorUpdateExistingParam 700 updateExisting.MemoryStoreID = memoryStoreID 701 return BetaOutputBehaviorUnionParam{OfUpdateExisting: &updateExisting} 702 } 703 704 // Only one field can be non-zero. 705 // 706 // Use [param.IsOmitted] to confirm if a field is set. 707 type BetaOutputBehaviorUnionParam struct { 708 OfCreateNew *BetaOutputBehaviorCreateNewParam `json:",omitzero,inline"` 709 OfUpdateExisting *BetaOutputBehaviorUpdateExistingParam `json:",omitzero,inline"` 710 paramUnion 711 } 712 713 func (u BetaOutputBehaviorUnionParam) MarshalJSON() ([]byte, error) { 714 return param.MarshalUnion(u, u.OfCreateNew, u.OfUpdateExisting) 715 } 716 func (u *BetaOutputBehaviorUnionParam) UnmarshalJSON(data []byte) error { 717 return apijson.UnmarshalRoot(data, u) 718 } 719 720 func (u *BetaOutputBehaviorUnionParam) asAny() any { 721 if !param.IsOmitted(u.OfCreateNew) { 722 return u.OfCreateNew 723 } else if !param.IsOmitted(u.OfUpdateExisting) { 724 return u.OfUpdateExisting 725 } 726 return nil 727 } 728 729 // Returns a pointer to the underlying variant's property, if present. 730 func (u BetaOutputBehaviorUnionParam) GetMemoryStoreID() *string { 731 if vt := u.OfUpdateExisting; vt != nil { 732 return &vt.MemoryStoreID 733 } 734 return nil 735 } 736 737 // Returns a pointer to the underlying variant's property, if present. 738 func (u BetaOutputBehaviorUnionParam) GetType() *string { 739 if vt := u.OfCreateNew; vt != nil { 740 return (*string)(&vt.Type) 741 } else if vt := u.OfUpdateExisting; vt != nil { 742 return (*string)(&vt.Type) 743 } 744 return nil 745 } 746 747 func init() { 748 apijson.RegisterUnion[BetaOutputBehaviorUnionParam]( 749 "type", 750 apijson.Discriminator[BetaOutputBehaviorCreateNewParam]("create_new"), 751 apijson.Discriminator[BetaOutputBehaviorUpdateExistingParam]("update_existing"), 752 ) 753 } 754 755 // The default destination: the job creates a new output memory store as a clone of 756 // the memory_store input and writes the consolidated memories into it. The input 757 // store is never mutated. 758 type BetaOutputBehaviorCreateNew struct { 759 // Any of "create_new". 760 Type BetaOutputBehaviorCreateNewType `json:"type" api:"required"` 761 // JSON contains metadata for fields, check presence with [respjson.Field.Valid]. 762 JSON struct { 763 Type respjson.Field 764 ExtraFields map[string]respjson.Field 765 raw string 766 } `json:"-"` 767 } 768 769 // Returns the unmodified JSON received from the API 770 func (r BetaOutputBehaviorCreateNew) RawJSON() string { return r.JSON.raw } 771 func (r *BetaOutputBehaviorCreateNew) UnmarshalJSON(data []byte) error { 772 return apijson.UnmarshalRoot(data, r) 773 } 774 775 // ToParam converts this BetaOutputBehaviorCreateNew to a 776 // BetaOutputBehaviorCreateNewParam. 777 // 778 // Warning: the fields of the param type will not be present. ToParam should only 779 // be used at the last possible moment before sending a request. Test for this with 780 // BetaOutputBehaviorCreateNewParam.Overrides() 781 func (r BetaOutputBehaviorCreateNew) ToParam() BetaOutputBehaviorCreateNewParam { 782 return param.Override[BetaOutputBehaviorCreateNewParam](json.RawMessage(r.RawJSON())) 783 } 784 785 type BetaOutputBehaviorCreateNewType string 786 787 const ( 788 BetaOutputBehaviorCreateNewTypeCreateNew BetaOutputBehaviorCreateNewType = "create_new" 789 ) 790 791 // The default destination: the job creates a new output memory store as a clone of 792 // the memory_store input and writes the consolidated memories into it. The input 793 // store is never mutated. 794 // 795 // The property Type is required. 796 type BetaOutputBehaviorCreateNewParam struct { 797 // Any of "create_new". 798 Type BetaOutputBehaviorCreateNewType `json:"type,omitzero" api:"required"` 799 paramObj 800 } 801 802 func (r BetaOutputBehaviorCreateNewParam) MarshalJSON() (data []byte, err error) { 803 type shadow BetaOutputBehaviorCreateNewParam 804 return param.MarshalObject(r, (*shadow)(&r)) 805 } 806 func (r *BetaOutputBehaviorCreateNewParam) UnmarshalJSON(data []byte) error { 807 return apijson.UnmarshalRoot(data, r) 808 } 809 810 // The job writes the consolidated memories into this existing memory store instead 811 // of creating one. In EAP the store must be the job's own memory_store input, so 812 // the job consolidates the store in place. 813 type BetaOutputBehaviorUpdateExisting struct { 814 MemoryStoreID string `json:"memory_store_id" api:"required"` 815 // Any of "update_existing". 816 Type BetaOutputBehaviorUpdateExistingType `json:"type" api:"required"` 817 // JSON contains metadata for fields, check presence with [respjson.Field.Valid]. 818 JSON struct { 819 MemoryStoreID respjson.Field 820 Type respjson.Field 821 ExtraFields map[string]respjson.Field 822 raw string 823 } `json:"-"` 824 } 825 826 // Returns the unmodified JSON received from the API 827 func (r BetaOutputBehaviorUpdateExisting) RawJSON() string { return r.JSON.raw } 828 func (r *BetaOutputBehaviorUpdateExisting) UnmarshalJSON(data []byte) error { 829 return apijson.UnmarshalRoot(data, r) 830 } 831 832 // ToParam converts this BetaOutputBehaviorUpdateExisting to a 833 // BetaOutputBehaviorUpdateExistingParam. 834 // 835 // Warning: the fields of the param type will not be present. ToParam should only 836 // be used at the last possible moment before sending a request. Test for this with 837 // BetaOutputBehaviorUpdateExistingParam.Overrides() 838 func (r BetaOutputBehaviorUpdateExisting) ToParam() BetaOutputBehaviorUpdateExistingParam { 839 return param.Override[BetaOutputBehaviorUpdateExistingParam](json.RawMessage(r.RawJSON())) 840 } 841 842 type BetaOutputBehaviorUpdateExistingType string 843 844 const ( 845 BetaOutputBehaviorUpdateExistingTypeUpdateExisting BetaOutputBehaviorUpdateExistingType = "update_existing" 846 ) 847 848 // The job writes the consolidated memories into this existing memory store instead 849 // of creating one. In EAP the store must be the job's own memory_store input, so 850 // the job consolidates the store in place. 851 // 852 // The properties MemoryStoreID, Type are required. 853 type BetaOutputBehaviorUpdateExistingParam struct { 854 MemoryStoreID string `json:"memory_store_id" api:"required"` 855 // Any of "update_existing". 856 Type BetaOutputBehaviorUpdateExistingType `json:"type,omitzero" api:"required"` 857 paramObj 858 } 859 860 func (r BetaOutputBehaviorUpdateExistingParam) MarshalJSON() (data []byte, err error) { 861 type shadow BetaOutputBehaviorUpdateExistingParam 862 return param.MarshalObject(r, (*shadow)(&r)) 863 } 864 func (r *BetaOutputBehaviorUpdateExistingParam) UnmarshalJSON(data []byte) error { 865 return apijson.UnmarshalRoot(data, r) 866 } 867 868 type BetaDreamNewParams struct { 869 Inputs []BetaDreamInputUnionParam `json:"inputs,omitzero" api:"required"` 870 // Model identifier and configuration applied to every pipeline stage. 871 Model BetaDreamNewParamsModelUnion `json:"model,omitzero" api:"required"` 872 Instructions param.Opt[string] `json:"instructions,omitzero"` 873 WorkspaceID param.Opt[string] `header:"anthropic-workspace-id,omitzero" json:"-"` 874 // The default destination: the job creates a new output memory store as a clone of 875 // the memory_store input and writes the consolidated memories into it. The input 876 // store is never mutated. 877 OutputBehavior BetaOutputBehaviorUnionParam `json:"output_behavior,omitzero"` 878 // Optional header to specify the beta version(s) you want to use. 879 Betas []AnthropicBeta `header:"anthropic-beta,omitzero" json:"-"` 880 paramObj 881 } 882 883 func (r BetaDreamNewParams) MarshalJSON() (data []byte, err error) { 884 type shadow BetaDreamNewParams 885 return param.MarshalObject(r, (*shadow)(&r)) 886 } 887 func (r *BetaDreamNewParams) UnmarshalJSON(data []byte) error { 888 return apijson.UnmarshalRoot(data, r) 889 } 890 891 // Only one field can be non-zero. 892 // 893 // Use [param.IsOmitted] to confirm if a field is set. 894 type BetaDreamNewParamsModelUnion struct { 895 OfString param.Opt[string] `json:",omitzero,inline"` 896 OfBetaDreamModelConfig *BetaDreamModelConfigParam `json:",omitzero,inline"` 897 paramUnion 898 } 899 900 func (u BetaDreamNewParamsModelUnion) MarshalJSON() ([]byte, error) { 901 return param.MarshalUnion(u, u.OfString, u.OfBetaDreamModelConfig) 902 } 903 func (u *BetaDreamNewParamsModelUnion) UnmarshalJSON(data []byte) error { 904 return apijson.UnmarshalRoot(data, u) 905 } 906 907 func (u *BetaDreamNewParamsModelUnion) asAny() any { 908 if !param.IsOmitted(u.OfString) { 909 return &u.OfString.Value 910 } else if !param.IsOmitted(u.OfBetaDreamModelConfig) { 911 return u.OfBetaDreamModelConfig 912 } 913 return nil 914 } 915 916 type BetaDreamGetParams struct { 917 WorkspaceID param.Opt[string] `header:"anthropic-workspace-id,omitzero" json:"-"` 918 // Optional header to specify the beta version(s) you want to use. 919 Betas []AnthropicBeta `header:"anthropic-beta,omitzero" json:"-"` 920 paramObj 921 } 922 923 type BetaDreamListParams struct { 924 // Return dreams with `created_at` strictly after this timestamp (exclusive lower 925 // bound, RFC 3339). Unset applies no lower bound. 926 CreatedAtGt param.Opt[time.Time] `query:"created_at[gt],omitzero" format:"date-time" json:"-"` 927 // Return dreams with `created_at` strictly before this timestamp (exclusive upper 928 // bound, RFC 3339). Unset applies no upper bound. 929 CreatedAtLt param.Opt[time.Time] `query:"created_at[lt],omitzero" format:"date-time" json:"-"` 930 // Query parameter for include_archived 931 IncludeArchived param.Opt[bool] `query:"include_archived,omitzero" json:"-"` 932 // Query parameter for limit 933 Limit param.Opt[int64] `query:"limit,omitzero" json:"-"` 934 // Query parameter for page 935 Page param.Opt[string] `query:"page,omitzero" json:"-"` 936 WorkspaceID param.Opt[string] `header:"anthropic-workspace-id,omitzero" json:"-"` 937 // Filter by lifecycle status. Repeat the parameter to match any of multiple 938 // statuses. Empty applies no status filter. 939 Statuses []BetaDreamStatus `query:"statuses,omitzero" json:"-"` 940 // Optional header to specify the beta version(s) you want to use. 941 Betas []AnthropicBeta `header:"anthropic-beta,omitzero" json:"-"` 942 paramObj 943 } 944 945 // URLQuery serializes [BetaDreamListParams]'s query parameters as `url.Values`. 946 func (r BetaDreamListParams) URLQuery() (v url.Values, err error) { 947 return apiquery.MarshalWithSettings(r, apiquery.QuerySettings{ 948 ArrayFormat: apiquery.ArrayQueryFormatBrackets, 949 NestedFormat: apiquery.NestedQueryFormatBrackets, 950 }) 951 } 952 953 type BetaDreamArchiveParams struct { 954 WorkspaceID param.Opt[string] `header:"anthropic-workspace-id,omitzero" json:"-"` 955 // Optional header to specify the beta version(s) you want to use. 956 Betas []AnthropicBeta `header:"anthropic-beta,omitzero" json:"-"` 957 paramObj 958 } 959 960 type BetaDreamCancelParams struct { 961 WorkspaceID param.Opt[string] `header:"anthropic-workspace-id,omitzero" json:"-"` 962 // Optional header to specify the beta version(s) you want to use. 963 Betas []AnthropicBeta `header:"anthropic-beta,omitzero" json:"-"` 964 paramObj 965 }