| 1 |
from __future__ import annotations |
| 2 |
|
| 3 |
from typing import List, Union, Iterable, Optional |
| 4 |
from datetime import datetime |
| 5 |
from itertools import chain |
| 6 |
|
| 7 |
import httpx2 |
| 8 |
|
| 9 |
from ..._types import Body, Omit, Query, Headers, NotGiven, omit, not_given |
| 10 |
from ..._utils import is_given, path_template, strip_not_given |
| 11 |
from ..._compat import cached_property |
| 12 |
from ..._resource import SyncAPIResource, AsyncAPIResource |
| 13 |
from ..._response import ( |
| 14 |
to_raw_response_wrapper, |
| 15 |
to_streamed_response_wrapper, |
| 16 |
async_to_raw_response_wrapper, |
| 17 |
async_to_streamed_response_wrapper, |
| 18 |
) |
| 19 |
from ...pagination import SyncPageCursor, AsyncPageCursor |
| 20 |
from ...types.beta import dream_create_params |
| 21 |
from ..._base_client import AsyncPaginator, make_request_options |
| 22 |
from ...types.beta.beta_dream import BetaDream |
| 23 |
from ...types.anthropic_beta_param import AnthropicBetaParam |
| 24 |
from ...types.beta.beta_dream_status import BetaDreamStatus |
| 25 |
from ...types.beta.beta_dream_input_param import BetaDreamInputParam |
| 26 |
from ...types.beta.beta_output_behavior_param import BetaOutputBehaviorParam |
| 27 |
|
| 28 |
__all__ = ["Dreams", "AsyncDreams"] |
| 29 |
|
| 30 |
|
| 31 |
class Dreams(SyncAPIResource): |
| 32 |
@cached_property |
| 33 |
def with_raw_response(self) -> DreamsWithRawResponse: |
| 34 |
""" |
| 35 |
This property can be used as a prefix for any HTTP method call to return |
| 36 |
the raw response object instead of the parsed content. |
| 37 |
|
| 38 |
For more information, see https://www.github.com/anthropics/anthropic-sdk-python#accessing-raw-response-data-eg-headers |
| 39 |
""" |
| 40 |
return DreamsWithRawResponse(self) |
| 41 |
|
| 42 |
@cached_property |
| 43 |
def with_streaming_response(self) -> DreamsWithStreamingResponse: |
| 44 |
""" |
| 45 |
An alternative to `.with_raw_response` that doesn't eagerly read the response body. |
| 46 |
|
| 47 |
For more information, see https://www.github.com/anthropics/anthropic-sdk-python#with_streaming_response |
| 48 |
""" |
| 49 |
return DreamsWithStreamingResponse(self) |
| 50 |
|
| 51 |
def create( |
| 52 |
self, |
| 53 |
*, |
| 54 |
inputs: Iterable[BetaDreamInputParam], |
| 55 |
model: dream_create_params.Model, |
| 56 |
instructions: Optional[str] | Omit = omit, |
| 57 |
output_behavior: BetaOutputBehaviorParam | Omit = omit, |
| 58 |
betas: List[AnthropicBetaParam] | Omit = omit, |
| 59 |
workspace_id: str | Omit = omit, |
| 60 |
# Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs. |
| 61 |
# The extra values given here take precedence over values defined on the client or passed to this method. |
| 62 |
extra_headers: Headers | None = None, |
| 63 |
extra_query: Query | None = None, |
| 64 |
extra_body: Body | None = None, |
| 65 |
timeout: float | httpx2.Timeout | None | NotGiven = not_given, |
| 66 |
) -> BetaDream: |
| 67 |
""" |
| 68 |
Start an asynchronous job that uses past sessions to produce a reorganized |
| 69 |
version of a memory store and get back the dream to poll for the result. |
| 70 |
|
| 71 |
By default the dream writes its result to a new memory store and doesn't change |
| 72 |
the input memory store. The response has `status` set to `pending` and an empty |
| 73 |
`outputs` array. Poll the dream until `status` is `completed`, `failed`, or |
| 74 |
`canceled`. |
| 75 |
|
| 76 |
See the |
| 77 |
[Dreams guide](https://platform.claude.com/docs/en/managed-agents/dreams#create-a-dream) |
| 78 |
to learn more about creating dreams. |
| 79 |
|
| 80 |
Args: |
| 81 |
inputs: The memory store and sessions for the dream to read, as exactly one |
| 82 |
`memory_store` entry and exactly one `sessions` entry. |
| 83 |
|
| 84 |
model: The model that runs a dream, given as a model ID or as an object with `id` and |
| 85 |
`speed`. |
| 86 |
|
| 87 |
In the object form, `speed` can only be `standard`. |
| 88 |
|
| 89 |
The |
| 90 |
[limits table in the Dreams guide](https://platform.claude.com/docs/en/managed-agents/dreams#limits) |
| 91 |
lists the supported models. |
| 92 |
|
| 93 |
instructions: Guidance that steers how the dream reads the sessions and organizes the output |
| 94 |
memory store, from 1 to 4,096 characters. |
| 95 |
|
| 96 |
See the |
| 97 |
[Dreams guide](https://platform.claude.com/docs/en/managed-agents/dreams#steer-with-instructions) |
| 98 |
for what kinds of instructions work well. |
| 99 |
|
| 100 |
output_behavior: Which memory store a dream writes its result to. Defaults to `create_new` when |
| 101 |
left out of a create request. |
| 102 |
|
| 103 |
betas: Optional header to specify the beta version(s) you want to use. |
| 104 |
|
| 105 |
workspace_id: Optional header to select the Workspace for this request. The value is a |
| 106 |
Workspace ID (for example, `wrkspc_011CZkZaBF1tNoB5wlCeusgy`). |
| 107 |
|
| 108 |
Only needed for credentials that can act on more than one Workspace. A |
| 109 |
credential that belongs to a specific Workspace may omit it; if sent, it must |
| 110 |
match that Workspace. |
| 111 |
|
| 112 |
extra_headers: Send extra headers |
| 113 |
|
| 114 |
extra_query: Add additional query parameters to the request |
| 115 |
|
| 116 |
extra_body: Add additional JSON properties to the request |
| 117 |
|
| 118 |
timeout: Override the client-level default timeout for this request, in seconds |
| 119 |
""" |
| 120 |
extra_headers = { |
| 121 |
**strip_not_given( |
| 122 |
{ |
| 123 |
"anthropic-beta": ",".join(chain((str(e) for e in betas), ["dreaming-2026-04-21"])) |
| 124 |
if is_given(betas) |
| 125 |
else not_given, |
| 126 |
"anthropic-workspace-id": workspace_id, |
| 127 |
} |
| 128 |
), |
| 129 |
**(extra_headers or {}), |
| 130 |
} |
| 131 |
extra_headers = {"anthropic-beta": "dreaming-2026-04-21", **(extra_headers or {})} |
| 132 |
return self._post( |
| 133 |
"/v1/dreams?beta=true", |
| 134 |
body={ |
| 135 |
"inputs": inputs, |
| 136 |
"model": model, |
| 137 |
"instructions": instructions, |
| 138 |
"output_behavior": output_behavior, |
| 139 |
}, |
| 140 |
options=make_request_options( |
| 141 |
extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout |
| 142 |
), |
| 143 |
cast_to=BetaDream, |
| 144 |
) |
| 145 |
|
| 146 |
def retrieve( |
| 147 |
self, |
| 148 |
dream_id: str, |
| 149 |
*, |
| 150 |
betas: List[AnthropicBetaParam] | Omit = omit, |
| 151 |
workspace_id: str | Omit = omit, |
| 152 |
# Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs. |
| 153 |
# The extra values given here take precedence over values defined on the client or passed to this method. |
| 154 |
extra_headers: Headers | None = None, |
| 155 |
extra_query: Query | None = None, |
| 156 |
extra_body: Body | None = None, |
| 157 |
timeout: float | httpx2.Timeout | None | NotGiven = not_given, |
| 158 |
) -> BetaDream: |
| 159 |
""" |
| 160 |
Get a dream by ID to check its status, output memory store, and token usage. |
| 161 |
|
| 162 |
Archived dreams are returned too. |
| 163 |
|
| 164 |
See the |
| 165 |
[Dreams guide](https://platform.claude.com/docs/en/managed-agents/dreams#track-progress) |
| 166 |
for how to poll a dream and what each status means. |
| 167 |
|
| 168 |
Args: |
| 169 |
dream_id: The ID of the dream to get (`drm_...`). |
| 170 |
|
| 171 |
betas: Optional header to specify the beta version(s) you want to use. |
| 172 |
|
| 173 |
workspace_id: Optional header to select the Workspace for this request. The value is a |
| 174 |
Workspace ID (for example, `wrkspc_011CZkZaBF1tNoB5wlCeusgy`). |
| 175 |
|
| 176 |
Only needed for credentials that can act on more than one Workspace. A |
| 177 |
credential that belongs to a specific Workspace may omit it; if sent, it must |
| 178 |
match that Workspace. |
| 179 |
|
| 180 |
extra_headers: Send extra headers |
| 181 |
|
| 182 |
extra_query: Add additional query parameters to the request |
| 183 |
|
| 184 |
extra_body: Add additional JSON properties to the request |
| 185 |
|
| 186 |
timeout: Override the client-level default timeout for this request, in seconds |
| 187 |
""" |
| 188 |
if not dream_id: |
| 189 |
raise ValueError(f"Expected a non-empty value for `dream_id` but received {dream_id!r}") |
| 190 |
extra_headers = { |
| 191 |
**strip_not_given( |
| 192 |
{ |
| 193 |
"anthropic-beta": ",".join(chain((str(e) for e in betas), ["dreaming-2026-04-21"])) |
| 194 |
if is_given(betas) |
| 195 |
else not_given, |
| 196 |
"anthropic-workspace-id": workspace_id, |
| 197 |
} |
| 198 |
), |
| 199 |
**(extra_headers or {}), |
| 200 |
} |
| 201 |
extra_headers = {"anthropic-beta": "dreaming-2026-04-21", **(extra_headers or {})} |
| 202 |
return self._get( |
| 203 |
path_template("/v1/dreams/{dream_id}?beta=true", dream_id=dream_id), |
| 204 |
options=make_request_options( |
| 205 |
extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout |
| 206 |
), |
| 207 |
cast_to=BetaDream, |
| 208 |
) |
| 209 |
|
| 210 |
def list( |
| 211 |
self, |
| 212 |
*, |
| 213 |
created_at_gt: Union[str, datetime] | Omit = omit, |
| 214 |
created_at_lt: Union[str, datetime] | Omit = omit, |
| 215 |
include_archived: bool | Omit = omit, |
| 216 |
limit: int | Omit = omit, |
| 217 |
page: str | Omit = omit, |
| 218 |
statuses: List[BetaDreamStatus] | Omit = omit, |
| 219 |
betas: List[AnthropicBetaParam] | Omit = omit, |
| 220 |
workspace_id: str | Omit = omit, |
| 221 |
# Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs. |
| 222 |
# The extra values given here take precedence over values defined on the client or passed to this method. |
| 223 |
extra_headers: Headers | None = None, |
| 224 |
extra_query: Query | None = None, |
| 225 |
extra_body: Body | None = None, |
| 226 |
timeout: float | httpx2.Timeout | None | NotGiven = not_given, |
| 227 |
) -> SyncPageCursor[BetaDream]: |
| 228 |
""" |
| 229 |
List the dreams in the workspace, newest first. |
| 230 |
|
| 231 |
Archived dreams are left out unless `include_archived` is `true`. |
| 232 |
|
| 233 |
See the |
| 234 |
[Dreams guide](https://platform.claude.com/docs/en/managed-agents/dreams#list-dreams) |
| 235 |
for how to page through dreams. |
| 236 |
|
| 237 |
Args: |
| 238 |
created_at_gt: Return only dreams created after this time (exclusive), in RFC 3339. |
| 239 |
|
| 240 |
created_at_lt: Return only dreams created before this time (exclusive), in RFC 3339. |
| 241 |
|
| 242 |
include_archived: Whether to include archived dreams. Defaults to `false`. |
| 243 |
|
| 244 |
limit: The maximum number of dreams to return, from 1 to 100. Defaults to 20. |
| 245 |
|
| 246 |
page: The cursor for the page to return, taken from `next_page` in a previous |
| 247 |
response. |
| 248 |
|
| 249 |
Leave it out to get the first page. |
| 250 |
|
| 251 |
statuses: Return only dreams that have one of these statuses. |
| 252 |
|
| 253 |
Repeat the parameter to give more than one status. Leave it out to return dreams |
| 254 |
of every status. |
| 255 |
|
| 256 |
betas: Optional header to specify the beta version(s) you want to use. |
| 257 |
|
| 258 |
workspace_id: Optional header to select the Workspace for this request. The value is a |
| 259 |
Workspace ID (for example, `wrkspc_011CZkZaBF1tNoB5wlCeusgy`). |
| 260 |
|
| 261 |
Only needed for credentials that can act on more than one Workspace. A |
| 262 |
credential that belongs to a specific Workspace may omit it; if sent, it must |
| 263 |
match that Workspace. |
| 264 |
|
| 265 |
extra_headers: Send extra headers |
| 266 |
|
| 267 |
extra_query: Add additional query parameters to the request |
| 268 |
|
| 269 |
extra_body: Add additional JSON properties to the request |
| 270 |
|
| 271 |
timeout: Override the client-level default timeout for this request, in seconds |
| 272 |
""" |
| 273 |
extra_headers = { |
| 274 |
**strip_not_given( |
| 275 |
{ |
| 276 |
"anthropic-beta": ",".join(chain((str(e) for e in betas), ["dreaming-2026-04-21"])) |
| 277 |
if is_given(betas) |
| 278 |
else not_given, |
| 279 |
"anthropic-workspace-id": workspace_id, |
| 280 |
} |
| 281 |
), |
| 282 |
**(extra_headers or {}), |
| 283 |
} |
| 284 |
extra_headers = {"anthropic-beta": "dreaming-2026-04-21", **(extra_headers or {})} |
| 285 |
return self._get_api_list( |
| 286 |
"/v1/dreams?beta=true", |
| 287 |
page=SyncPageCursor[BetaDream], |
| 288 |
options=make_request_options( |
| 289 |
extra_headers=extra_headers, |
| 290 |
extra_query=extra_query, |
| 291 |
extra_body=extra_body, |
| 292 |
timeout=timeout, |
| 293 |
query={ |
| 294 |
"created_at[gt]": created_at_gt, |
| 295 |
"created_at[lt]": created_at_lt, |
| 296 |
"include_archived": include_archived, |
| 297 |
"limit": limit, |
| 298 |
"page": page, |
| 299 |
"statuses": statuses, |
| 300 |
}, |
| 301 |
), |
| 302 |
model=BetaDream, |
| 303 |
) |
| 304 |
|
| 305 |
def archive( |
| 306 |
self, |
| 307 |
dream_id: str, |
| 308 |
*, |
| 309 |
betas: List[AnthropicBetaParam] | Omit = omit, |
| 310 |
workspace_id: str | Omit = omit, |
| 311 |
# Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs. |
| 312 |
# The extra values given here take precedence over values defined on the client or passed to this method. |
| 313 |
extra_headers: Headers | None = None, |
| 314 |
extra_query: Query | None = None, |
| 315 |
extra_body: Body | None = None, |
| 316 |
timeout: float | httpx2.Timeout | None | NotGiven = not_given, |
| 317 |
) -> BetaDream: |
| 318 |
""" |
| 319 |
Hide a `completed`, `failed`, or `canceled` dream from the default list of |
| 320 |
dreams. |
| 321 |
|
| 322 |
Archiving a `pending` or `running` dream returns a 400 error, so cancel it |
| 323 |
first. Archiving an archived dream returns it unchanged. An archived dream can |
| 324 |
still be fetched by ID. Archiving can't be undone. |
| 325 |
|
| 326 |
See the |
| 327 |
[Dreams guide](https://platform.claude.com/docs/en/managed-agents/dreams#archive-a-dream) |
| 328 |
to learn more about archiving dreams. |
| 329 |
|
| 330 |
Args: |
| 331 |
dream_id: The ID of the dream to archive (`drm_...`). |
| 332 |
|
| 333 |
betas: Optional header to specify the beta version(s) you want to use. |
| 334 |
|
| 335 |
workspace_id: Optional header to select the Workspace for this request. The value is a |
| 336 |
Workspace ID (for example, `wrkspc_011CZkZaBF1tNoB5wlCeusgy`). |
| 337 |
|
| 338 |
Only needed for credentials that can act on more than one Workspace. A |
| 339 |
credential that belongs to a specific Workspace may omit it; if sent, it must |
| 340 |
match that Workspace. |
| 341 |
|
| 342 |
extra_headers: Send extra headers |
| 343 |
|
| 344 |
extra_query: Add additional query parameters to the request |
| 345 |
|
| 346 |
extra_body: Add additional JSON properties to the request |
| 347 |
|
| 348 |
timeout: Override the client-level default timeout for this request, in seconds |
| 349 |
""" |
| 350 |
if not dream_id: |
| 351 |
raise ValueError(f"Expected a non-empty value for `dream_id` but received {dream_id!r}") |
| 352 |
extra_headers = { |
| 353 |
**strip_not_given( |
| 354 |
{ |
| 355 |
"anthropic-beta": ",".join(chain((str(e) for e in betas), ["dreaming-2026-04-21"])) |
| 356 |
if is_given(betas) |
| 357 |
else not_given, |
| 358 |
"anthropic-workspace-id": workspace_id, |
| 359 |
} |
| 360 |
), |
| 361 |
**(extra_headers or {}), |
| 362 |
} |
| 363 |
extra_headers = {"anthropic-beta": "dreaming-2026-04-21", **(extra_headers or {})} |
| 364 |
return self._post( |
| 365 |
path_template("/v1/dreams/{dream_id}/archive?beta=true", dream_id=dream_id), |
| 366 |
options=make_request_options( |
| 367 |
extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout |
| 368 |
), |
| 369 |
cast_to=BetaDream, |
| 370 |
) |
| 371 |
|
| 372 |
def cancel( |
| 373 |
self, |
| 374 |
dream_id: str, |
| 375 |
*, |
| 376 |
betas: List[AnthropicBetaParam] | Omit = omit, |
| 377 |
workspace_id: str | Omit = omit, |
| 378 |
# Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs. |
| 379 |
# The extra values given here take precedence over values defined on the client or passed to this method. |
| 380 |
extra_headers: Headers | None = None, |
| 381 |
extra_query: Query | None = None, |
| 382 |
extra_body: Body | None = None, |
| 383 |
timeout: float | httpx2.Timeout | None | NotGiven = not_given, |
| 384 |
) -> BetaDream: |
| 385 |
""" |
| 386 |
Stop a `pending` or `running` dream. |
| 387 |
|
| 388 |
The response shows `status` as `canceled`, unless the dream reached `completed` |
| 389 |
or `failed` first. `usage` can keep changing after the response. Canceling a |
| 390 |
`canceled` dream returns it unchanged. Canceling a `completed` or `failed` dream |
| 391 |
returns a 400 error. |
| 392 |
|
| 393 |
See the |
| 394 |
[Dreams guide](https://platform.claude.com/docs/en/managed-agents/dreams#cancel-a-dream) |
| 395 |
to learn more about canceling dreams. |
| 396 |
|
| 397 |
Args: |
| 398 |
dream_id: The ID of the dream to cancel (`drm_...`). |
| 399 |
|
| 400 |
betas: Optional header to specify the beta version(s) you want to use. |
| 401 |
|
| 402 |
workspace_id: Optional header to select the Workspace for this request. The value is a |
| 403 |
Workspace ID (for example, `wrkspc_011CZkZaBF1tNoB5wlCeusgy`). |
| 404 |
|
| 405 |
Only needed for credentials that can act on more than one Workspace. A |
| 406 |
credential that belongs to a specific Workspace may omit it; if sent, it must |
| 407 |
match that Workspace. |
| 408 |
|
| 409 |
extra_headers: Send extra headers |
| 410 |
|
| 411 |
extra_query: Add additional query parameters to the request |
| 412 |
|
| 413 |
extra_body: Add additional JSON properties to the request |
| 414 |
|
| 415 |
timeout: Override the client-level default timeout for this request, in seconds |
| 416 |
""" |
| 417 |
if not dream_id: |
| 418 |
raise ValueError(f"Expected a non-empty value for `dream_id` but received {dream_id!r}") |
| 419 |
extra_headers = { |
| 420 |
**strip_not_given( |
| 421 |
{ |
| 422 |
"anthropic-beta": ",".join(chain((str(e) for e in betas), ["dreaming-2026-04-21"])) |
| 423 |
if is_given(betas) |
| 424 |
else not_given, |
| 425 |
"anthropic-workspace-id": workspace_id, |
| 426 |
} |
| 427 |
), |
| 428 |
**(extra_headers or {}), |
| 429 |
} |
| 430 |
extra_headers = {"anthropic-beta": "dreaming-2026-04-21", **(extra_headers or {})} |
| 431 |
return self._post( |
| 432 |
path_template("/v1/dreams/{dream_id}/cancel?beta=true", dream_id=dream_id), |
| 433 |
options=make_request_options( |
| 434 |
extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout |
| 435 |
), |
| 436 |
cast_to=BetaDream, |
| 437 |
) |
| 438 |
|
| 439 |
|
| 440 |
class AsyncDreams(AsyncAPIResource): |
| 441 |
@cached_property |
| 442 |
def with_raw_response(self) -> AsyncDreamsWithRawResponse: |
| 443 |
""" |
| 444 |
This property can be used as a prefix for any HTTP method call to return |
| 445 |
the raw response object instead of the parsed content. |
| 446 |
|
| 447 |
For more information, see https://www.github.com/anthropics/anthropic-sdk-python#accessing-raw-response-data-eg-headers |
| 448 |
""" |
| 449 |
return AsyncDreamsWithRawResponse(self) |
| 450 |
|
| 451 |
@cached_property |
| 452 |
def with_streaming_response(self) -> AsyncDreamsWithStreamingResponse: |
| 453 |
""" |
| 454 |
An alternative to `.with_raw_response` that doesn't eagerly read the response body. |
| 455 |
|
| 456 |
For more information, see https://www.github.com/anthropics/anthropic-sdk-python#with_streaming_response |
| 457 |
""" |
| 458 |
return AsyncDreamsWithStreamingResponse(self) |
| 459 |
|
| 460 |
async def create( |
| 461 |
self, |
| 462 |
*, |
| 463 |
inputs: Iterable[BetaDreamInputParam], |
| 464 |
model: dream_create_params.Model, |
| 465 |
instructions: Optional[str] | Omit = omit, |
| 466 |
output_behavior: BetaOutputBehaviorParam | Omit = omit, |
| 467 |
betas: List[AnthropicBetaParam] | Omit = omit, |
| 468 |
workspace_id: str | Omit = omit, |
| 469 |
# Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs. |
| 470 |
# The extra values given here take precedence over values defined on the client or passed to this method. |
| 471 |
extra_headers: Headers | None = None, |
| 472 |
extra_query: Query | None = None, |
| 473 |
extra_body: Body | None = None, |
| 474 |
timeout: float | httpx2.Timeout | None | NotGiven = not_given, |
| 475 |
) -> BetaDream: |
| 476 |
""" |
| 477 |
Start an asynchronous job that uses past sessions to produce a reorganized |
| 478 |
version of a memory store and get back the dream to poll for the result. |
| 479 |
|
| 480 |
By default the dream writes its result to a new memory store and doesn't change |
| 481 |
the input memory store. The response has `status` set to `pending` and an empty |
| 482 |
`outputs` array. Poll the dream until `status` is `completed`, `failed`, or |
| 483 |
`canceled`. |
| 484 |
|
| 485 |
See the |
| 486 |
[Dreams guide](https://platform.claude.com/docs/en/managed-agents/dreams#create-a-dream) |
| 487 |
to learn more about creating dreams. |
| 488 |
|
| 489 |
Args: |
| 490 |
inputs: The memory store and sessions for the dream to read, as exactly one |
| 491 |
`memory_store` entry and exactly one `sessions` entry. |
| 492 |
|
| 493 |
model: The model that runs a dream, given as a model ID or as an object with `id` and |
| 494 |
`speed`. |
| 495 |
|
| 496 |
In the object form, `speed` can only be `standard`. |
| 497 |
|
| 498 |
The |
| 499 |
[limits table in the Dreams guide](https://platform.claude.com/docs/en/managed-agents/dreams#limits) |
| 500 |
lists the supported models. |
| 501 |
|
| 502 |
instructions: Guidance that steers how the dream reads the sessions and organizes the output |
| 503 |
memory store, from 1 to 4,096 characters. |
| 504 |
|
| 505 |
See the |
| 506 |
[Dreams guide](https://platform.claude.com/docs/en/managed-agents/dreams#steer-with-instructions) |
| 507 |
for what kinds of instructions work well. |
| 508 |
|
| 509 |
output_behavior: Which memory store a dream writes its result to. Defaults to `create_new` when |
| 510 |
left out of a create request. |
| 511 |
|
| 512 |
betas: Optional header to specify the beta version(s) you want to use. |
| 513 |
|
| 514 |
workspace_id: Optional header to select the Workspace for this request. The value is a |
| 515 |
Workspace ID (for example, `wrkspc_011CZkZaBF1tNoB5wlCeusgy`). |
| 516 |
|
| 517 |
Only needed for credentials that can act on more than one Workspace. A |
| 518 |
credential that belongs to a specific Workspace may omit it; if sent, it must |
| 519 |
match that Workspace. |
| 520 |
|
| 521 |
extra_headers: Send extra headers |
| 522 |
|
| 523 |
extra_query: Add additional query parameters to the request |
| 524 |
|
| 525 |
extra_body: Add additional JSON properties to the request |
| 526 |
|
| 527 |
timeout: Override the client-level default timeout for this request, in seconds |
| 528 |
""" |
| 529 |
extra_headers = { |
| 530 |
**strip_not_given( |
| 531 |
{ |
| 532 |
"anthropic-beta": ",".join(chain((str(e) for e in betas), ["dreaming-2026-04-21"])) |
| 533 |
if is_given(betas) |
| 534 |
else not_given, |
| 535 |
"anthropic-workspace-id": workspace_id, |
| 536 |
} |
| 537 |
), |
| 538 |
**(extra_headers or {}), |
| 539 |
} |
| 540 |
extra_headers = {"anthropic-beta": "dreaming-2026-04-21", **(extra_headers or {})} |
| 541 |
return await self._post( |
| 542 |
"/v1/dreams?beta=true", |
| 543 |
body={ |
| 544 |
"inputs": inputs, |
| 545 |
"model": model, |
| 546 |
"instructions": instructions, |
| 547 |
"output_behavior": output_behavior, |
| 548 |
}, |
| 549 |
options=make_request_options( |
| 550 |
extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout |
| 551 |
), |
| 552 |
cast_to=BetaDream, |
| 553 |
) |
| 554 |
|
| 555 |
async def retrieve( |
| 556 |
self, |
| 557 |
dream_id: str, |
| 558 |
*, |
| 559 |
betas: List[AnthropicBetaParam] | Omit = omit, |
| 560 |
workspace_id: str | Omit = omit, |
| 561 |
# Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs. |
| 562 |
# The extra values given here take precedence over values defined on the client or passed to this method. |
| 563 |
extra_headers: Headers | None = None, |
| 564 |
extra_query: Query | None = None, |
| 565 |
extra_body: Body | None = None, |
| 566 |
timeout: float | httpx2.Timeout | None | NotGiven = not_given, |
| 567 |
) -> BetaDream: |
| 568 |
""" |
| 569 |
Get a dream by ID to check its status, output memory store, and token usage. |
| 570 |
|
| 571 |
Archived dreams are returned too. |
| 572 |
|
| 573 |
See the |
| 574 |
[Dreams guide](https://platform.claude.com/docs/en/managed-agents/dreams#track-progress) |
| 575 |
for how to poll a dream and what each status means. |
| 576 |
|
| 577 |
Args: |
| 578 |
dream_id: The ID of the dream to get (`drm_...`). |
| 579 |
|
| 580 |
betas: Optional header to specify the beta version(s) you want to use. |
| 581 |
|
| 582 |
workspace_id: Optional header to select the Workspace for this request. The value is a |
| 583 |
Workspace ID (for example, `wrkspc_011CZkZaBF1tNoB5wlCeusgy`). |
| 584 |
|
| 585 |
Only needed for credentials that can act on more than one Workspace. A |
| 586 |
credential that belongs to a specific Workspace may omit it; if sent, it must |
| 587 |
match that Workspace. |
| 588 |
|
| 589 |
extra_headers: Send extra headers |
| 590 |
|
| 591 |
extra_query: Add additional query parameters to the request |
| 592 |
|
| 593 |
extra_body: Add additional JSON properties to the request |
| 594 |
|
| 595 |
timeout: Override the client-level default timeout for this request, in seconds |
| 596 |
""" |
| 597 |
if not dream_id: |
| 598 |
raise ValueError(f"Expected a non-empty value for `dream_id` but received {dream_id!r}") |
| 599 |
extra_headers = { |
| 600 |
**strip_not_given( |
| 601 |
{ |
| 602 |
"anthropic-beta": ",".join(chain((str(e) for e in betas), ["dreaming-2026-04-21"])) |
| 603 |
if is_given(betas) |
| 604 |
else not_given, |
| 605 |
"anthropic-workspace-id": workspace_id, |
| 606 |
} |
| 607 |
), |
| 608 |
**(extra_headers or {}), |
| 609 |
} |
| 610 |
extra_headers = {"anthropic-beta": "dreaming-2026-04-21", **(extra_headers or {})} |
| 611 |
return await self._get( |
| 612 |
path_template("/v1/dreams/{dream_id}?beta=true", dream_id=dream_id), |
| 613 |
options=make_request_options( |
| 614 |
extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout |
| 615 |
), |
| 616 |
cast_to=BetaDream, |
| 617 |
) |
| 618 |
|
| 619 |
def list( |
| 620 |
self, |
| 621 |
*, |
| 622 |
created_at_gt: Union[str, datetime] | Omit = omit, |
| 623 |
created_at_lt: Union[str, datetime] | Omit = omit, |
| 624 |
include_archived: bool | Omit = omit, |
| 625 |
limit: int | Omit = omit, |
| 626 |
page: str | Omit = omit, |
| 627 |
statuses: List[BetaDreamStatus] | Omit = omit, |
| 628 |
betas: List[AnthropicBetaParam] | Omit = omit, |
| 629 |
workspace_id: str | Omit = omit, |
| 630 |
# Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs. |
| 631 |
# The extra values given here take precedence over values defined on the client or passed to this method. |
| 632 |
extra_headers: Headers | None = None, |
| 633 |
extra_query: Query | None = None, |
| 634 |
extra_body: Body | None = None, |
| 635 |
timeout: float | httpx2.Timeout | None | NotGiven = not_given, |
| 636 |
) -> AsyncPaginator[BetaDream, AsyncPageCursor[BetaDream]]: |
| 637 |
""" |
| 638 |
List the dreams in the workspace, newest first. |
| 639 |
|
| 640 |
Archived dreams are left out unless `include_archived` is `true`. |
| 641 |
|
| 642 |
See the |
| 643 |
[Dreams guide](https://platform.claude.com/docs/en/managed-agents/dreams#list-dreams) |
| 644 |
for how to page through dreams. |
| 645 |
|
| 646 |
Args: |
| 647 |
created_at_gt: Return only dreams created after this time (exclusive), in RFC 3339. |
| 648 |
|
| 649 |
created_at_lt: Return only dreams created before this time (exclusive), in RFC 3339. |
| 650 |
|
| 651 |
include_archived: Whether to include archived dreams. Defaults to `false`. |
| 652 |
|
| 653 |
limit: The maximum number of dreams to return, from 1 to 100. Defaults to 20. |
| 654 |
|
| 655 |
page: The cursor for the page to return, taken from `next_page` in a previous |
| 656 |
response. |
| 657 |
|
| 658 |
Leave it out to get the first page. |
| 659 |
|
| 660 |
statuses: Return only dreams that have one of these statuses. |
| 661 |
|
| 662 |
Repeat the parameter to give more than one status. Leave it out to return dreams |
| 663 |
of every status. |
| 664 |
|
| 665 |
betas: Optional header to specify the beta version(s) you want to use. |
| 666 |
|
| 667 |
workspace_id: Optional header to select the Workspace for this request. The value is a |
| 668 |
Workspace ID (for example, `wrkspc_011CZkZaBF1tNoB5wlCeusgy`). |
| 669 |
|
| 670 |
Only needed for credentials that can act on more than one Workspace. A |
| 671 |
credential that belongs to a specific Workspace may omit it; if sent, it must |
| 672 |
match that Workspace. |
| 673 |
|
| 674 |
extra_headers: Send extra headers |
| 675 |
|
| 676 |
extra_query: Add additional query parameters to the request |
| 677 |
|
| 678 |
extra_body: Add additional JSON properties to the request |
| 679 |
|
| 680 |
timeout: Override the client-level default timeout for this request, in seconds |
| 681 |
""" |
| 682 |
extra_headers = { |
| 683 |
**strip_not_given( |
| 684 |
{ |
| 685 |
"anthropic-beta": ",".join(chain((str(e) for e in betas), ["dreaming-2026-04-21"])) |
| 686 |
if is_given(betas) |
| 687 |
else not_given, |
| 688 |
"anthropic-workspace-id": workspace_id, |
| 689 |
} |
| 690 |
), |
| 691 |
**(extra_headers or {}), |
| 692 |
} |
| 693 |
extra_headers = {"anthropic-beta": "dreaming-2026-04-21", **(extra_headers or {})} |
| 694 |
return self._get_api_list( |
| 695 |
"/v1/dreams?beta=true", |
| 696 |
page=AsyncPageCursor[BetaDream], |
| 697 |
options=make_request_options( |
| 698 |
extra_headers=extra_headers, |
| 699 |
extra_query=extra_query, |
| 700 |
extra_body=extra_body, |
| 701 |
timeout=timeout, |
| 702 |
query={ |
| 703 |
"created_at[gt]": created_at_gt, |
| 704 |
"created_at[lt]": created_at_lt, |
| 705 |
"include_archived": include_archived, |
| 706 |
"limit": limit, |
| 707 |
"page": page, |
| 708 |
"statuses": statuses, |
| 709 |
}, |
| 710 |
), |
| 711 |
model=BetaDream, |
| 712 |
) |
| 713 |
|
| 714 |
async def archive( |
| 715 |
self, |
| 716 |
dream_id: str, |
| 717 |
*, |
| 718 |
betas: List[AnthropicBetaParam] | Omit = omit, |
| 719 |
workspace_id: str | Omit = omit, |
| 720 |
# Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs. |
| 721 |
# The extra values given here take precedence over values defined on the client or passed to this method. |
| 722 |
extra_headers: Headers | None = None, |
| 723 |
extra_query: Query | None = None, |
| 724 |
extra_body: Body | None = None, |
| 725 |
timeout: float | httpx2.Timeout | None | NotGiven = not_given, |
| 726 |
) -> BetaDream: |
| 727 |
""" |
| 728 |
Hide a `completed`, `failed`, or `canceled` dream from the default list of |
| 729 |
dreams. |
| 730 |
|
| 731 |
Archiving a `pending` or `running` dream returns a 400 error, so cancel it |
| 732 |
first. Archiving an archived dream returns it unchanged. An archived dream can |
| 733 |
still be fetched by ID. Archiving can't be undone. |
| 734 |
|
| 735 |
See the |
| 736 |
[Dreams guide](https://platform.claude.com/docs/en/managed-agents/dreams#archive-a-dream) |
| 737 |
to learn more about archiving dreams. |
| 738 |
|
| 739 |
Args: |
| 740 |
dream_id: The ID of the dream to archive (`drm_...`). |
| 741 |
|
| 742 |
betas: Optional header to specify the beta version(s) you want to use. |
| 743 |
|
| 744 |
workspace_id: Optional header to select the Workspace for this request. The value is a |
| 745 |
Workspace ID (for example, `wrkspc_011CZkZaBF1tNoB5wlCeusgy`). |
| 746 |
|
| 747 |
Only needed for credentials that can act on more than one Workspace. A |
| 748 |
credential that belongs to a specific Workspace may omit it; if sent, it must |
| 749 |
match that Workspace. |
| 750 |
|
| 751 |
extra_headers: Send extra headers |
| 752 |
|
| 753 |
extra_query: Add additional query parameters to the request |
| 754 |
|
| 755 |
extra_body: Add additional JSON properties to the request |
| 756 |
|
| 757 |
timeout: Override the client-level default timeout for this request, in seconds |
| 758 |
""" |
| 759 |
if not dream_id: |
| 760 |
raise ValueError(f"Expected a non-empty value for `dream_id` but received {dream_id!r}") |
| 761 |
extra_headers = { |
| 762 |
**strip_not_given( |
| 763 |
{ |
| 764 |
"anthropic-beta": ",".join(chain((str(e) for e in betas), ["dreaming-2026-04-21"])) |
| 765 |
if is_given(betas) |
| 766 |
else not_given, |
| 767 |
"anthropic-workspace-id": workspace_id, |
| 768 |
} |
| 769 |
), |
| 770 |
**(extra_headers or {}), |
| 771 |
} |
| 772 |
extra_headers = {"anthropic-beta": "dreaming-2026-04-21", **(extra_headers or {})} |
| 773 |
return await self._post( |
| 774 |
path_template("/v1/dreams/{dream_id}/archive?beta=true", dream_id=dream_id), |
| 775 |
options=make_request_options( |
| 776 |
extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout |
| 777 |
), |
| 778 |
cast_to=BetaDream, |
| 779 |
) |
| 780 |
|
| 781 |
async def cancel( |
| 782 |
self, |
| 783 |
dream_id: str, |
| 784 |
*, |
| 785 |
betas: List[AnthropicBetaParam] | Omit = omit, |
| 786 |
workspace_id: str | Omit = omit, |
| 787 |
# Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs. |
| 788 |
# The extra values given here take precedence over values defined on the client or passed to this method. |
| 789 |
extra_headers: Headers | None = None, |
| 790 |
extra_query: Query | None = None, |
| 791 |
extra_body: Body | None = None, |
| 792 |
timeout: float | httpx2.Timeout | None | NotGiven = not_given, |
| 793 |
) -> BetaDream: |
| 794 |
""" |
| 795 |
Stop a `pending` or `running` dream. |
| 796 |
|
| 797 |
The response shows `status` as `canceled`, unless the dream reached `completed` |
| 798 |
or `failed` first. `usage` can keep changing after the response. Canceling a |
| 799 |
`canceled` dream returns it unchanged. Canceling a `completed` or `failed` dream |
| 800 |
returns a 400 error. |
| 801 |
|
| 802 |
See the |
| 803 |
[Dreams guide](https://platform.claude.com/docs/en/managed-agents/dreams#cancel-a-dream) |
| 804 |
to learn more about canceling dreams. |
| 805 |
|
| 806 |
Args: |
| 807 |
dream_id: The ID of the dream to cancel (`drm_...`). |
| 808 |
|
| 809 |
betas: Optional header to specify the beta version(s) you want to use. |
| 810 |
|
| 811 |
workspace_id: Optional header to select the Workspace for this request. The value is a |
| 812 |
Workspace ID (for example, `wrkspc_011CZkZaBF1tNoB5wlCeusgy`). |
| 813 |
|
| 814 |
Only needed for credentials that can act on more than one Workspace. A |
| 815 |
credential that belongs to a specific Workspace may omit it; if sent, it must |
| 816 |
match that Workspace. |
| 817 |
|
| 818 |
extra_headers: Send extra headers |
| 819 |
|
| 820 |
extra_query: Add additional query parameters to the request |
| 821 |
|
| 822 |
extra_body: Add additional JSON properties to the request |
| 823 |
|
| 824 |
timeout: Override the client-level default timeout for this request, in seconds |
| 825 |
""" |
| 826 |
if not dream_id: |
| 827 |
raise ValueError(f"Expected a non-empty value for `dream_id` but received {dream_id!r}") |
| 828 |
extra_headers = { |
| 829 |
**strip_not_given( |
| 830 |
{ |
| 831 |
"anthropic-beta": ",".join(chain((str(e) for e in betas), ["dreaming-2026-04-21"])) |
| 832 |
if is_given(betas) |
| 833 |
else not_given, |
| 834 |
"anthropic-workspace-id": workspace_id, |
| 835 |
} |
| 836 |
), |
| 837 |
**(extra_headers or {}), |
| 838 |
} |
| 839 |
extra_headers = {"anthropic-beta": "dreaming-2026-04-21", **(extra_headers or {})} |
| 840 |
return await self._post( |
| 841 |
path_template("/v1/dreams/{dream_id}/cancel?beta=true", dream_id=dream_id), |
| 842 |
options=make_request_options( |
| 843 |
extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout |
| 844 |
), |
| 845 |
cast_to=BetaDream, |
| 846 |
) |
| 847 |
|
| 848 |
|
| 849 |
class DreamsWithRawResponse: |
| 850 |
def __init__(self, dreams: Dreams) -> None: |
| 851 |
self._dreams = dreams |
| 852 |
|
| 853 |
self.create = to_raw_response_wrapper( |
| 854 |
dreams.create, |
| 855 |
) |
| 856 |
self.retrieve = to_raw_response_wrapper( |
| 857 |
dreams.retrieve, |
| 858 |
) |
| 859 |
self.list = to_raw_response_wrapper( |
| 860 |
dreams.list, |
| 861 |
) |
| 862 |
self.archive = to_raw_response_wrapper( |
| 863 |
dreams.archive, |
| 864 |
) |
| 865 |
self.cancel = to_raw_response_wrapper( |
| 866 |
dreams.cancel, |
| 867 |
) |
| 868 |
|
| 869 |
|
| 870 |
class AsyncDreamsWithRawResponse: |
| 871 |
def __init__(self, dreams: AsyncDreams) -> None: |
| 872 |
self._dreams = dreams |
| 873 |
|
| 874 |
self.create = async_to_raw_response_wrapper( |
| 875 |
dreams.create, |
| 876 |
) |
| 877 |
self.retrieve = async_to_raw_response_wrapper( |
| 878 |
dreams.retrieve, |
| 879 |
) |
| 880 |
self.list = async_to_raw_response_wrapper( |
| 881 |
dreams.list, |
| 882 |
) |
| 883 |
self.archive = async_to_raw_response_wrapper( |
| 884 |
dreams.archive, |
| 885 |
) |
| 886 |
self.cancel = async_to_raw_response_wrapper( |
| 887 |
dreams.cancel, |
| 888 |
) |
| 889 |
|
| 890 |
|
| 891 |
class DreamsWithStreamingResponse: |
| 892 |
def __init__(self, dreams: Dreams) -> None: |
| 893 |
self._dreams = dreams |
| 894 |
|
| 895 |
self.create = to_streamed_response_wrapper( |
| 896 |
dreams.create, |
| 897 |
) |
| 898 |
self.retrieve = to_streamed_response_wrapper( |
| 899 |
dreams.retrieve, |
| 900 |
) |
| 901 |
self.list = to_streamed_response_wrapper( |
| 902 |
dreams.list, |
| 903 |
) |
| 904 |
self.archive = to_streamed_response_wrapper( |
| 905 |
dreams.archive, |
| 906 |
) |
| 907 |
self.cancel = to_streamed_response_wrapper( |
| 908 |
dreams.cancel, |
| 909 |
) |
| 910 |
|
| 911 |
|
| 912 |
class AsyncDreamsWithStreamingResponse: |
| 913 |
def __init__(self, dreams: AsyncDreams) -> None: |
| 914 |
self._dreams = dreams |
| 915 |
|
| 916 |
self.create = async_to_streamed_response_wrapper( |
| 917 |
dreams.create, |
| 918 |
) |
| 919 |
self.retrieve = async_to_streamed_response_wrapper( |
| 920 |
dreams.retrieve, |
| 921 |
) |
| 922 |
self.list = async_to_streamed_response_wrapper( |
| 923 |
dreams.list, |
| 924 |
) |
| 925 |
self.archive = async_to_streamed_response_wrapper( |
| 926 |
dreams.archive, |
| 927 |
) |
| 928 |
self.cancel = async_to_streamed_response_wrapper( |
| 929 |
dreams.cancel, |
| 930 |
) |