Follow Discord
Sweep 22 Oct 2026 · 04:32Z Build v2.1.308 527 read Stable v2.1.308 Latest v2.1.308 Next v2.1.308 Feeds RSS JSON llms.txt llms-full.txt Unofficial
One change · api

typescript changedcli-sdks-libraries/sdks/typescript

Nearest release: v2.1.307, published an hour after this site recorded the change. Shown because the two are within 24 hours of each other. Nothing here says the release caused the edit.

Recorded here
Lines+25added
Lines−25removed
From line 55 where the diff opens
First seen 14 Aug 2026 this site's first read of the page
Recorded edits11to this page, all time

The whole hunk

from line 55, old and new numbered
/
lines
from line 55
5555}
5656```
5757 
58For authentication options including Workload Identity Federation, see [Authentication](https://platform.claude.com/docs/en/manage-claude/authentication). If your API key is a [personal or service account key](https://platform.claude.com/docs/en/manage-claude/authentication#key-types) with access to multiple workspaces, set the workspace ID in the `anthropic-workspace-id` request header; [Select a workspace](https://platform.claude.com/docs/en/manage-claude/authentication#select-a-workspace) shows the per-request option for this SDK.
58For authentication options including Workload Identity Federation, see [Authentication](https://platform.claude.com/docs/en/manage-claude/authentication). If your API key is a [personal or service account key](https://platform.claude.com/docs/en/manage-claude/authentication#key-types) that isn't scoped to a workspace, set the workspace ID in the `anthropic-workspace-id` request header; [Select a workspace](https://platform.claude.com/docs/en/manage-claude/authentication#select-a-workspace) shows the per-request option for this SDK.
5959 
6060## Request and response types
6161 
62This library includes TypeScript definitions for all request parameters and response fields. You may import and use them like so:
62This library includes TypeScript definitions for all request parameters and response fields. You can import and use them as follows:
6363 
6464```typescript
6565const client = new Anthropic({
from line 136
136136console.log(message);
137137```
138138 
139Streaming with `client.messages.stream(...)` exposes various helpers for your convenience including event handlers and accumulation.
139Streaming with `client.messages.stream(...)` exposes various helpers for your convenience, including event handlers and accumulation.
140140 
141Alternatively, you can use `client.messages.create({ ..., stream: true })` which only returns an async iterable of the events in the stream and thus uses less memory (it does not build up a final message object for you).
141Alternatively, you can use `client.messages.create({ ..., stream: true })`, which only returns an async iterable of the events in the stream and thus uses less memory (it does not build up a final message object for you).
142142 
143143## Tool helpers
144144 
145This SDK provides helpers for making it easy to create and run tools in the Messages API. You can use Zod schemas or JSON Schemas to describe the input to a tool. You can then run those tools using the `client.beta.messages.toolRunner()` method. This method handles passing the inputs generated by the chosen model into the right tool and passing the result back to the model.
145This SDK provides helpers for creating and running tools in the Messages API. You can use Zod schemas or JSON Schemas to describe the input to a tool. You can then run those tools using the `client.beta.messages.toolRunner()` method. This method handles passing the inputs generated by the chosen model into the right tool and passing the result back to the model.
146146 
147147For more details on tool use, see [Tool use with Claude](https://platform.claude.com/docs/en/agents-and-tools/tool-use/overview). To run the browser use tool or the computer use tool with this SDK, see [Browser and computer use with the SDK toolsets](https://platform.claude.com/docs/en/agents-and-tools/tool-use/browser-use-sdk).
148148 
from line 314
314314 
315315### Getting results from a batch
316316 
317Once a Message Batch has been processed, indicated by `.processing_status === 'ended'`, you can access the results with `.batches.results()`
317Once a Message Batch has been processed, indicated by `.processing_status === 'ended'`, you can access the results with `.batches.results()`:
318318 
319319```typescript
320320const results = await client.messages.batches.results(batch.id);
from line 334
334334* an `fs.ReadStream`
335335* the return value of the `toFile` helper
336336 
337Set the content type explicitly as the Files API will not infer it for you:
337Set the content type explicitly as the Files API does not infer it for you:
338338 
339339```typescript
340340import fs from "node:fs";
from line 369
369369 
370370## Handling errors
371371 
372When the library is unable to connect to the API, or if the API returns a non-success status code (that is, 4xx or 5xx response), a subclass of `APIError` is thrown:
372When the library is unable to connect to the API, or if the API returns a non-success status code (that is, a 4xx or 5xx response), a subclass of `APIError` is thrown:
373373 
374374```typescript
375375const message = await client.messages
from line 407
407407 
408408> For more information on debugging requests, see [Request ID](https://platform.claude.com/docs/en/api/errors#request-id).
409409 
410All object responses in the SDK provide a `_request_id` property which is added from the `request-id` response header so that you can quickly log failing requests and report them back to Anthropic.
410All object responses in the SDK provide a `_request_id` property, which is added from the `request-id` response header so that you can log failing requests and report them back to Anthropic.
411411 
412412```typescript
413413const message = await client.messages.create({
from line 443
443443 
444444## Timeouts
445445 
446By default requests time out after 10 minutes. However if you have specified a large `max_tokens` value and are *not* streaming, the default timeout will be calculated dynamically using the formula:
446By default requests time out after 10 minutes. However, if you have specified a large `max_tokens` value and are *not* streaming, the default timeout will be calculated dynamically using the formula:
447447 
448448```typescript
449449const minimum = 10 * 60;
from line 479
479479## Long requests
480480 
481481<Warning>
482 Consider using the streaming [Messages API](https://platform.claude.com/docs/en/cli-sdks-libraries/sdks/typescript#streaming-responses) for longer running requests.
482 Consider using the [streaming Messages API](https://platform.claude.com/docs/en/cli-sdks-libraries/sdks/typescript#streaming-responses) for longer-running requests.
483483</Warning>
484484 
485Avoid setting a large `max_tokens` value without using streaming. Some networks may drop idle connections after a certain period of time, which can cause the request to fail or [time out](https://platform.claude.com/docs/en/cli-sdks-libraries/sdks/typescript#timeouts) without receiving a response from Anthropic.
485Avoid setting a large `max_tokens` value without using streaming. Some networks might drop idle connections after a certain period of time, which can cause the request to fail or [time out](https://platform.claude.com/docs/en/cli-sdks-libraries/sdks/typescript#timeouts) without receiving a response from Anthropic.
486486 
487487This SDK also throws an error if a non-streaming request is expected to be above roughly 10 minutes long. Passing `stream: true` or [overriding](https://platform.claude.com/docs/en/cli-sdks-libraries/sdks/typescript#timeouts) the `timeout` option at the client or request level disables this error.
488488 
489An expected request latency longer than the [timeout](https://platform.claude.com/docs/en/cli-sdks-libraries/sdks/typescript#timeouts) for a non-streaming request will result in the client terminating the connection and retrying without receiving a response.
489An expected request latency longer than the [timeout](https://platform.claude.com/docs/en/cli-sdks-libraries/sdks/typescript#timeouts) for a non-streaming request will result in the client ending the connection and retrying without receiving a response.
490490 
491491When supported by the `fetch` implementation, the SDK sets a [TCP socket keep-alive](https://tldp.org/HOWTO/TCP-Keepalive-HOWTO/overview.html) option to reduce the impact of idle connection timeouts on some networks. This can be [overridden](https://platform.claude.com/docs/en/cli-sdks-libraries/sdks/typescript#configuring-proxies) by configuring a custom proxy.
492492 
from line 526
526526 
527527If you need to, you can override it by setting default headers on a per-request basis.
528528 
529Be aware that doing so may result in incorrect types and other unexpected or undefined behavior in the SDK.
529Be aware that doing so might result in incorrect types and other unexpected or undefined behavior in the SDK.
530530 
531531```typescript
532532const client = new Anthropic();
from line 547
547547 
548548The "raw" `Response` returned by `fetch()` can be accessed through the `.asResponse()` method on the `APIPromise` type that all methods return. This method returns as soon as the headers for a successful response are received and does not consume the response body, so you are free to write custom parsing or streaming logic.
549549 
550You can also use the `.withResponse()` method to get the raw `Response` along with the parsed data. Unlike `.asResponse()` this method consumes the body, returning once it is parsed.
550You can also use the `.withResponse()` method to get the raw `Response` along with the parsed data. Unlike `.asResponse()`, this method consumes the body, returning once it is parsed.
551551 
552552```typescript
553553const client = new Anthropic();
from line 584
584584You can configure the log level in two ways:
585585 
5865861. Through the `ANTHROPIC_LOG` environment variable
5872. Using the `logLevel` client option (overrides the environment variable if set)
5872. Through the `logLevel` client option (overrides the environment variable if set)
588588 
589589```typescript
590590const client = new Anthropic({
from line 600
600600* `'error'` - Show only errors
601601* `'off'` - Disable all logging
602602 
603At the `'debug'` level, all HTTP requests and responses are logged, including headers and bodies. Some authentication-related headers are redacted, but sensitive data in request and response bodies may still be visible.
603At the `'debug'` level, all HTTP requests and responses are logged, including headers and bodies. Some authentication-related headers are redacted, but sensitive data in request and response bodies might still be visible.
604604 
605605#### Custom logger
606606 
607607By default, this library logs to `globalThis.console`. You can also provide a custom logger. Most logging libraries are supported, including [pino](https://www.npmjs.com/package/pino), [winston](https://www.npmjs.com/package/winston), [bunyan](https://www.npmjs.com/package/bunyan), [consola](https://www.npmjs.com/package/consola), [signale](https://www.npmjs.com/package/signale), and [@std/log](https://jsr.io/@std/log). If your logger doesn't work, open an issue.
608608 
609When providing a custom logger, the `logLevel` option still controls which messages are emitted; messages below the configured level will not be sent to your logger.
609When providing a custom logger, the `logLevel` option still controls which messages are emitted; messages below the configured level are not sent to your logger.
610610 
611611```typescript
612612import pino from "pino";
from line 621
621621 
622622### Making custom/undocumented requests
623623 
624This library is typed for convenient access to the documented API. If you need to access undocumented endpoints, params, or response properties, the library can still be used.
624This library is typed for convenient access to the documented API. If you need to access undocumented endpoints, parameters, or response properties, the library can still be used.
625625 
626626#### Undocumented endpoints
627627 
from line 636
636636 
637637#### Undocumented request parameters
638638 
639To make requests using undocumented parameters, you may use `// @ts-expect-error` on the undocumented parameter. This library doesn't validate at runtime that the request matches the type, so any extra values you send will be sent as-is.
639To make requests using undocumented parameters, you can use `// @ts-expect-error` on the undocumented parameter. This library doesn't validate at runtime that the request matches the type, so any extra values you send are sent as-is.
640640 
641641```typescript
642642client.messages.create({
from line 646
646646});
647647```
648648 
649For requests with the `GET` verb, any extra parameters will be in the query; all other requests will send the extra parameter in the body.
649For requests with the `GET` verb, any extra parameters are in the query; all other requests send the extra parameter in the body.
650650 
651651If you want to explicitly send an extra argument, you can do so with the `query`, `body`, and `headers` request options.
652652 
653653#### Undocumented response properties
654654 
655To access undocumented response properties, you may access the response object with `// @ts-expect-error` on the response object, or cast the response object to the requisite type. Like the request parameters, the SDK does not validate or strip extra properties from the response from the API.
655To access undocumented response properties, you can access the response object with `// @ts-expect-error` on the response object, or cast the response object to the requisite type. Like the request parameters, the SDK does not validate or strip extra properties from the response from the API.
656656 
657657### Customizing the fetch client
658658 
659By default, this library expects a global `fetch` function is defined.
659By default, this library requires a global `fetch` function to be defined.
660660 
661661If you want to use a different `fetch` function, you can either polyfill the global:
662662 
from line 787
787787This package generally follows [SemVer](https://semver.org/spec/v2.0.0.html) conventions, though certain backward-incompatible changes may be released as minor versions:
788788 
7897891. Changes that only affect static types, without breaking runtime behavior.
7902. Changes to library internals which are technically public but not intended or documented for external use.
7902. Changes to library internals that are technically public but not intended or documented for external use.
7917913. Changes that aren't expected to impact the vast majority of users in practice.
792792 
793793Backward compatibility is taken seriously to ensure you can rely on a smooth upgrade experience.
Feedback