Features
- api: add the beta analytics list of projects in the new projects experience
- api: add the organization_url_fetch_disabled error code
Bug Fixes
-
client: do not retry a dropped response body when x-should-retry is false
If the connection drops or times out while a response body is read, and the response had
x-should-retry: false, the client now raises the error after one request instead of retrying. The error it raises is unchanged. -
client: name the host, cause and timeout in connection error messages
-
client: raise APITimeoutError when a request hook replaces the request's extensions
-
client: show middleware the client's default headers, including credentials
APIRequest.headersnow holds the SDK's headers,default_headersand credentials such as theauthorizationheader built fromapi_keyorauth_token, under the headers of the call. The client's header names are lowercase, and the call's keep their casing. Middleware that logsrequest.headersshould redact credentials, matching names without regard to case.Middleware that writes
{"x-team": "mine", **request.headers}now sends the client'sx-team, if it has one. Put your header after**request.headersto override it.Middleware that only sets
authorizationwhen it's missing now keeps the client's key, and checks for a missingauthorizationheader now pass. A case-sensitive check forAuthorizationstill finds it missing. Don't forwardrequest.headersto another client, because it now includes this client's key.Middleware can now remove
anthropic-workspace-idandanthropic-user-profile-idby setting them toomit.On Bedrock, an
anthropic-betavalue indefault_headersis sent asanthropic_betawhen the client has middleware, and spaces around the values are trimmed. -
client: stop memory growing when types are created per request
-
client: use the API's error message, not the whole response body, as the error message
-
credentials: keep a base URL's password out of token endpoint errors
-
credentials: match the loopback host exactly in the token endpoint https check
A plain
http://base URL is allowed for the token exchange only when its host is exactlylocalhost,127.0.0.1or::1. A URL that only starts that way, such ashttp://localhost.example.comorhttp://localhost@example.com, used to be accepted and now raisesCredentialsError, so usehttps://for any other host. A loopback URL with a username, such ashttp://user@localhost:8080, used to be refused and is now accepted. -
environments: fail a
writeoreditthat the memory store does not saveIn the environment worker, a
writeoreditof a memory file now uploads the content first. If the store refuses it, another session changed the memory, or the store does not confirm the upload within 30 seconds, the call returns an error with the reason. The file then stays as it was, unless the store saved an upload that it did not confirm: the next sync downloads that version.After the first download, each try of a background sync request now times out after 30 seconds, even if the client's
timeoutis longer. -
environments: upload a change to a memory file that follows a failed
write -
parse: keep a field description that sits beside a
$refAn enum or nested-model field written as
Field(description="...")now keeps its description in the schema thattransform_schema()returns, and so in theoutput_config.formatof every method that takes a type asoutput_format. So does the docstring of aRootModelover an enum or a model. What is sent for such a type changes, so answers can change, and the change invalidates any prompt cache for that conversation thread.The SDK now sends these descriptions, so the API can reject one schema that it accepted before: a hand-written schema, passed through
transform_schema(), whoseallOfmembers give one property the same$refbut different descriptions. Use the same description in each member. -
streaming: raise APIConnectionError when a JSONL stream drops
A connection that fails while a JSONL response is read, such as Message Batches results, used to raise the HTTP library's own error, such as
httpx2.RemoteProtocolError,httpx2.ReadErrororhttpx2.ReadTimeout.
Iterating the results now yields every complete line that arrived and then raisesanthropic.APIConnectionError, or its subclassanthropic.APITimeoutErrorfor a timeout, with the original error as its__cause__.
Code that catcheshttpx2errors around batch results should catchanthropic.APIConnectionErrorinstead.
The request is not sent again. -
streaming: raise APIConnectionError when the connection drops mid-stream
A connection that fails while a stream is read used to raise the HTTP library's own error, such as
httpx2.RemoteProtocolError,httpx2.ReadErrororhttpx2.ReadTimeout.
The stream now raisesanthropic.APIConnectionError, or its subclassanthropic.APITimeoutErrorfor a timeout, with the original error as its__cause__.
Code that catcheshttpx2errors around a stream should catchanthropic.APIConnectionErrorinstead.
The request is not sent again. -
tools: give the model the error's whole message when the API refuses a tool's result
The session tool runner's error result now ends with the error's
message, which has the status, the API's own message, the error code, the request ID, the path, the type and the details. -
tools: refuse a
replace_alledit whose result is over the file size limitThis applies to a
replace_alledit of two or more matches. The limit ismax_file_bytes, 256 KiB by default, and the file is left unchanged.
Performance Improvements
-
streaming: create text_stream on first use
-
structured outputs: stop building a message class for each thread and after garbage collection
parse(), the tool runner and message threads now returnParsedMessageorParsedBetaMessageitself, asstream()does, not a generated subclass namedParsedMessage[TypeVar]. The same holds forParsedTextBlockandParsedBetaTextBlock. Sorepr()no longer shows[TypeVar], and these messages can be pickled. -
structured outputs: transform an
output_formattype's JSON schema once -
tools: read only tool and status events from a session's history
Chores
- api: spell EDC in capitals in new type names
- api: spell EFS in capitals in new type names
- docs: clarify what a federation rule's match must contain
- docs: update example request bodies
- docs: use example.com in example email addresses
- internal: simplify how request schemas are described
Documentation
- api: clarify that max_tokens applies to each model call
- api: clarify when SCIM-provisioned RBAC groups can be changed
- api: say to retry storage_not_ready in a minute