Skip to content

v2.17.0

Latest

Choose a tag to compare

@anthropic-sdks-releaser anthropic-sdks-releaser released this 03 Dec 18:31

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.headers now holds the SDK's headers, default_headers and credentials such as the authorization header built from api_key or auth_token, under the headers of the call. The client's header names are lowercase, and the call's keep their casing. Middleware that logs request.headers should redact credentials, matching names without regard to case.

    Middleware that writes {"x-team": "mine", **request.headers} now sends the client's x-team, if it has one. Put your header after **request.headers to override it.

    Middleware that only sets authorization when it's missing now keeps the client's key, and checks for a missing authorization header now pass. A case-sensitive check for Authorization still finds it missing. Don't forward request.headers to another client, because it now includes this client's key.

    Middleware can now remove anthropic-workspace-id and anthropic-user-profile-id by setting them to omit.

    On Bedrock, an anthropic-beta value in default_headers is sent as anthropic_beta when 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 exactly localhost, 127.0.0.1 or ::1. A URL that only starts that way, such as http://localhost.example.com or http://localhost@example.com, used to be accepted and now raises CredentialsError, so use https:// for any other host. A loopback URL with a username, such as http://user@localhost:8080, used to be refused and is now accepted.

  • environments: fail a write or edit that the memory store does not save

    In the environment worker, a write or edit of 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 timeout is longer.

  • environments: upload a change to a memory file that follows a failed write

  • parse: keep a field description that sits beside a $ref

    An enum or nested-model field written as Field(description="...") now keeps its description in the schema that transform_schema() returns, and so in the output_config.format of every method that takes a type as output_format. So does the docstring of a RootModel over 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(), whose allOf members give one property the same $ref but 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.ReadError or httpx2.ReadTimeout.
    Iterating the results now yields every complete line that arrived and then raises anthropic.APIConnectionError, or its subclass anthropic.APITimeoutError for a timeout, with the original error as its __cause__.
    Code that catches httpx2 errors around batch results should catch anthropic.APIConnectionError instead.
    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.ReadError or httpx2.ReadTimeout.
    The stream now raises anthropic.APIConnectionError, or its subclass anthropic.APITimeoutError for a timeout, with the original error as its __cause__.
    Code that catches httpx2 errors around a stream should catch anthropic.APIConnectionError instead.
    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_all edit whose result is over the file size limit

    This applies to a replace_all edit of two or more matches. The limit is max_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 return ParsedMessage or ParsedBetaMessage itself, as stream() does, not a generated subclass named ParsedMessage[TypeVar]. The same holds for ParsedTextBlock and ParsedBetaTextBlock. So repr() no longer shows [TypeVar], and these messages can be pickled.

  • structured outputs: transform an output_format type'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