anthropics/anthropic-sdk-python

`timeout` parameter doesn't seem to have any effect

ikbenale opened this issue · 3 comments

I'm not sure if I'm misunderstanding how to use the timeout parameter (ref) or what its purpose is, but I tried the following snippet:

from anthropic import Anthropic

client = Anthropic(timeout=0.1)
client.messages.create(model='claude-3-5-sonnet-20240620', max_tokens=1024, messages=[{'role': 'user', 'content': 'Write a 20 paragraph essay'}])

... and the request seems to take as much time as it wants, without a timeout error being thrown.

SDK version: 0.31.2

Hey @ikbenale, thanks for the bug report, this is happening because we have a custom default timeout for the messages.create() endpoint which is overriding the timeout set at the client-level.

While we work on fixing this you can ensure the timeout is applied correctly by passing it to the method call directly, e.g.

client.messages.create(
  model='claude-3-5-sonnet-20240620',
  max_tokens=1024,
  messages=[{'role': 'user', 'content': 'Write a 20 paragraph essay'}],
  timeout=0.1
)

It's also worth noting that this timeout is for a single request & by default we retry 2 times, if you do not want this behaviour you can instantiate the client with max_retries=0.

@ikbenale this was fixed in v0.32.0

Thanks @RobertCraigie! We'll try this out.