Skip to content

Commit c923bda

Browse files
committed
feat(api): add claude-3.7 + support for thinking
1 parent 4e48234 commit c923bda

File tree

13 files changed

+887
-125
lines changed

13 files changed

+887
-125
lines changed

README.md

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -262,7 +262,16 @@ await client.messages.create({ max_tokens: 1024, messages: [{ role: 'user', cont
262262

263263
### Timeouts
264264

265-
Requests time out after 10 minutes by default. You can configure this with a `timeout` option:
265+
By default requests time out after 10 minutes. However if you have specified a large `max_tokens` value and are
266+
*not* streaming, the default timeout will be calculated dynamically using the formula:
267+
```typescript
268+
const minimum = 10 * 60;
269+
const calculated = (60 * 60 * maxTokens) / 128_000;
270+
return calculated < minimum ? minimum * 1000 : calculated * 1000;
271+
```
272+
which will result in a timeout up to 60 minutes, scaled by the `max_tokens` parameter, unless overriden at the request or client level.
273+
274+
You can configure this with a `timeout` option:
266275

267276
<!-- prettier-ignore -->
268277
```ts
@@ -281,6 +290,24 @@ On timeout, an `APIConnectionTimeoutError` is thrown.
281290

282291
Note that requests which time out will be [retried twice by default](#retries).
283292

293+
### Long Requests
294+
295+
> [!IMPORTANT]
296+
> We highly encourage you use the streaming [Messages API](#streaming-responses) for longer running requests.
297+
298+
We do not recommend setting a large `max_tokens` values without using streaming.
299+
Some networks may drop idle connections after a certain period of time, which
300+
can cause the request to fail or [timeout](#timeouts) without receiving a response from Anthropic.
301+
302+
This SDK will also throw an error if a non-streaming request is expected to be above roughly 10 minutes long.
303+
Passing `stream: true` or [overriding](#timeouts) the `timeout` option at the client or request level disables this error.
304+
305+
An expected request latency longer than the [timeout](#timeouts) for a non-streaming request
306+
will result in the client terminating the connection and retrying without receiving a response.
307+
308+
When supported by the `fetch` implementation, we set a [TCP socket keep-alive](https://tldp.org/HOWTO/TCP-Keepalive-HOWTO/overview.html)
309+
option in order to reduce the impact of idle connection timeouts on some networks.
310+
284311
## Auto-pagination
285312

286313
List methods in the Anthropic API are paginated.

packages/vertex-sdk/yarn.lock

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@
2727
form-data-encoder "1.7.2"
2828
formdata-node "^4.3.2"
2929
node-fetch "^2.6.7"
30-
web-streams-polyfill "^3.2.1"
3130

3231
"@babel/code-frame@^7.0.0", "@babel/code-frame@^7.12.13", "@babel/code-frame@^7.22.13", "@babel/code-frame@^7.23.5":
3332
version "7.23.5"
@@ -3257,11 +3256,6 @@ [email protected]:
32573256
resolved "https://registry.yarnpkg.com/web-streams-polyfill/-/web-streams-polyfill-4.0.0-beta.3.tgz#2898486b74f5156095e473efe989dcf185047a38"
32583257
integrity sha512-QW95TCTaHmsYfHDybGMwO5IJIM93I/6vTRk+daHTWFPhwh+C8Cg7j7XyKrwrj8Ib6vYXe0ocYNrmzY4xAAN6ug==
32593258

3260-
web-streams-polyfill@^3.2.1:
3261-
version "3.3.2"
3262-
resolved "https://registry.yarnpkg.com/web-streams-polyfill/-/web-streams-polyfill-3.3.2.tgz#32e26522e05128203a7de59519be3c648004343b"
3263-
integrity sha512-3pRGuxRF5gpuZc0W+EpwQRmCD7gRqcDOMt688KmdlDAgAyaB1XlN0zq2njfDNm44XVdIouE7pZ6GzbdyH47uIQ==
3264-
32653259
webidl-conversions@^3.0.0:
32663260
version "3.0.1"
32673261
resolved "https://registry.yarnpkg.com/webidl-conversions/-/webidl-conversions-3.0.1.tgz#24534275e2a7bc6be7bc86611cc16ae0a5654871"

src/client.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import * as Opts from './internal/request-options';
1313
import { VERSION } from './version';
1414
import * as Errors from './error';
1515
import * as Pagination from './pagination';
16+
import { AnthropicError } from './error';
1617
import { AbstractPage, type PageParams, PageResponse } from './pagination';
1718
import * as Uploads from './uploads';
1819
import * as API from './resources/index';
@@ -430,6 +431,18 @@ export class BaseAnthropic {
430431
return url.toString();
431432
}
432433

434+
_calculateNonstreamingTimeout(maxTokens: number): number {
435+
const defaultTimeout = 10 * 60;
436+
const expectedTimeout = (60 * 60 * maxTokens) / 128_000;
437+
if (expectedTimeout > defaultTimeout) {
438+
throw new AnthropicError(
439+
'Streaming is strongly recommended for operations that may take longer than 10 minutes. ' +
440+
'See https://github.com/anthropics/anthropic-sdk-python#streaming-responses for more details',
441+
);
442+
}
443+
return defaultTimeout * 1000;
444+
}
445+
433446
/**
434447
* Used as a callback for mutating the given `FinalRequestOptions` object.
435448
*/

0 commit comments

Comments
 (0)