Skip to content

fix: increase default API timeout from 5min to 10min#733

Closed
TimeToBuildBob wants to merge 4 commits intomasterfrom
fix/issue-732-anthropic-timeout
Closed

fix: increase default API timeout from 5min to 10min#733
TimeToBuildBob wants to merge 4 commits intomasterfrom
fix/issue-732-anthropic-timeout

Conversation

@TimeToBuildBob
Copy link
Copy Markdown
Member

@TimeToBuildBob TimeToBuildBob commented Oct 17, 2025

Summary

Fixes #732 by increasing the default API timeout from 5 minutes to 10 minutes.

Problem

The 5-minute default timeout was causing unnecessary stalls and retries:

  • Requests would timeout at 5 minutes
  • Then succeed on retry (because they just needed more time)
  • Both OpenAI and Anthropic clients have 10-minute defaults
  • By setting our own 5-minute default, we were being MORE restrictive

Solution

Changed default timeout from 300s (5 min) to 600s (10 min) to match the OpenAI and Anthropic Python client defaults.

Changes

  • gptme/llm/llm_anthropic.py: Updated default timeout to 600s with clarified comments
  • gptme/llm/llm_openai.py: Updated default timeout to 600s with clarified comments
  • tests/test_llm_openai.py: Updated test expectations to match new 600s default

Research

Used Perplexity to verify client defaults:

  • OpenAI Python client: Default timeout is 10 minutes (600 seconds)
  • Anthropic Python client: Default timeout is 10 minutes (600 seconds)

Behavior

Before:

  • Timeout at 5 minutes → unnecessary retry → success
  • More restrictive than client defaults

After:

  • Timeout at 10 minutes (matches client behavior)
  • Users can still set custom timeout via LLM_API_TIMEOUT env var

Testing

  • ✅ All tests pass
  • ✅ Updated test_timeout_default to expect 600s
  • ✅ Pre-commit checks pass

Related


Important

Increase default API timeout from 5 to 10 minutes in llm_anthropic.py and llm_openai.py, aligning with client defaults and updating tests accordingly.

  • Behavior:
    • Increase default API timeout from 300s (5 min) to 600s (10 min) in llm_anthropic.py and llm_openai.py.
    • Aligns with OpenAI and Anthropic client defaults.
    • Users can override with LLM_API_TIMEOUT environment variable.
  • Tests:
    • Update test_timeout_default in test_llm_openai.py to expect 600s.
    • Add tests for custom and invalid timeout values in test_llm_openai.py.
  • Misc:
    • Clarified comments regarding timeout defaults in llm_anthropic.py and llm_openai.py.

This description was created by Ellipsis for 0d9a68a. You can customize this summary. It will automatically update as commits are pushed.

Implements Anthropic Claude native web search to address issue #492
(broken search due to bot detection on Google/DuckDuckGo).

Features:
- Environment variable configuration (GPTME_ANTHROPIC_WEB_SEARCH)
- Configurable max_uses parameter (GPTME_ANTHROPIC_WEB_SEARCH_MAX_USES)
- Seamless integration with existing tools
- Automatic web search - Claude decides when to use it
- Backward compatible (disabled by default)

Implementation:
- Added _create_web_search_tool() to create tool definition
- Modified _prepare_messages_for_api() to conditionally include web search
- Updated browser tool documentation
- Added comprehensive test suite (3 new tests, all passing)

Usage:
export GPTME_ANTHROPIC_WEB_SEARCH=true
gptme -m anthropic/claude-sonnet-4-5

Addresses: #492
The web search tool uses Anthropic's API structure (type, name, max_uses)
which differs from the SDK's ToolParam TypedDict (name, description, input_schema).
This is expected since web search is a newer feature where SDK types may lag API.

Fixes typecheck errors at lines 276, 278, and 344.
…search

- Add try/except for invalid GPTME_ANTHROPIC_WEB_SEARCH_MAX_USES values
- Add duplicate tool check to prevent multiple web search tools
- Add tests for both improvements
- Addresses automated review feedback from PR #723

Changes:
- Error handling: Falls back to default max_uses=5 if env var is invalid
- Duplicate prevention: Checks tools_dict for existing web_search_20250305
- Test coverage: Added test_web_search_invalid_max_uses and test_web_search_no_duplicate_tools
- All 5 web search tests passing
Addresses issue #732 where 5-minute default timeout was causing
unnecessary stalls and retries.

Changes:
- Increased default timeout from 300s (5min) to 600s (10min)
- Matches OpenAI and Anthropic client defaults
- Updated comments to clarify this matches client defaults
- Updated test expectations to match new 600s default

Rationale:
Both OpenAI and Anthropic Python clients have 10-minute defaults.
By setting our own 5-minute default, we were being more restrictive
than the clients themselves, causing requests that would succeed
within 10 minutes to timeout at 5 minutes and then succeed on retry.

The new 600s default aligns with client behavior while still allowing
users to set custom timeouts via LLM_API_TIMEOUT environment variable.

Fixes #732
Copy link
Copy Markdown
Contributor

@greptile-apps greptile-apps Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Greptile Overview

Greptile Summary

This PR addresses timeout issues by increasing the default API timeout from 5 minutes (300s) to 10 minutes (600s) for both OpenAI and Anthropic API clients. The change aligns gptme's timeout behavior with the native client library defaults, preventing unnecessary request failures and retries. The core issue was that gptme's custom 5-minute timeout was more restrictive than the underlying client defaults, causing requests to timeout prematurely and then succeed on retry when they just needed more time.

Additionally, the PR introduces Anthropic's native web search tool functionality, which provides a more reliable alternative to traditional web scraping methods that often get blocked by bot detection. This feature is configurable via environment variables and integrates cleanly with the existing tool system.

Important Files Changed

Changed Files
Filename Score Overview
gptme/llm/llm_openai.py 5/5 Updated default timeout from 300s to 600s to match OpenAI client defaults
gptme/llm/llm_anthropic.py 4/5 Updated timeout to 600s and added new native web search tool capability
tests/test_llm_openai.py 5/5 Updated test expectations to validate new 600-second timeout default
tests/test_llm_anthropic.py 5/5 Added comprehensive test coverage for new web search tool functionality
gptme/tools/browser.py 5/5 Added documentation for Anthropic's native web search configuration

Confidence score: 4/5

  • This PR is safe to merge with low risk of production issues
  • Score reflects solid timeout fix with well-tested web search feature addition, but deducted one point due to the substantial new web search functionality that wasn't mentioned in the PR description and could benefit from more testing in production
  • Pay close attention to gptme/llm/llm_anthropic.py for the new web search tool implementation and ensure the environment variable configuration works as expected

Sequence Diagram

sequenceDiagram
    participant User
    participant CLI/Client
    participant LLM Module
    participant Config
    participant OpenAI Client
    participant Anthropic Client
    participant API

    User->>CLI/Client: "Make API call with timeout configuration"
    CLI/Client->>Config: "get_env('LLM_API_TIMEOUT')"
    Config-->>CLI/Client: "timeout_str or None"
    CLI/Client->>LLM Module: "init(provider, config)"
    
    alt OpenAI Provider
        LLM Module->>Config: "get_env('LLM_API_TIMEOUT')"
        Config-->>LLM Module: "timeout_str or None"
        LLM Module->>LLM Module: "timeout = float(timeout_str) if timeout_str else 600.0"
        LLM Module->>OpenAI Client: "OpenAI(timeout=600.0)"
        OpenAI Client-->>LLM Module: "client instance"
    else Anthropic Provider
        LLM Module->>Config: "get_env('LLM_API_TIMEOUT')"
        Config-->>LLM Module: "timeout_str or None"
        LLM Module->>LLM Module: "timeout = float(timeout_str) if timeout_str else 600.0"
        LLM Module->>Anthropic Client: "Anthropic(timeout=600.0)"
        Anthropic Client-->>LLM Module: "client instance"
    end
    
    LLM Module-->>CLI/Client: "client initialized"
    CLI/Client->>LLM Module: "chat() or stream()"
    LLM Module->>API: "API call with 10-minute timeout"
    API-->>LLM Module: "response or timeout after 10 minutes"
    LLM Module-->>CLI/Client: "response"
    CLI/Client-->>User: "result"
Loading

Context used:

  • Context from dashboard - README.md file (source)

5 files reviewed, no comments

Edit Code Review Agent Settings | Greptile

Copy link
Copy Markdown
Contributor

@ellipsis-dev ellipsis-dev Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Important

Looks good to me! 👍

Reviewed everything up to 0d9a68a in 1 minute and 33 seconds. Click for details.
  • Reviewed 342 lines of code in 5 files
  • Skipped 0 files when reviewing.
  • Skipped posting 7 draft comments. View those below.
  • Modify your settings and rules to customize what types of comments Ellipsis leaves. And don't forget to react with 👍 or 👎 to teach Ellipsis.
1. gptme/llm/llm_anthropic.py:159
  • Draft comment:
    Default API timeout now defaults to 600s (from 300s), which aligns with client defaults. Consider whether you want to add explicit handling (or a clearer error message) when a non-numeric value is provided.
  • Reason this comment was not posted:
    Decided after close inspection that this draft comment was likely wrong and/or not actionable: usefulness confidence = 20% vs. threshold = 50% The first part about the timeout change is just informative and not actionable. The second part about error handling is a valid suggestion since the current code could crash with ValueError. However, this is a configuration value that would typically be set by developers/admins, not end users. The default value is sensible. The error would be obvious and easy to fix if it occurred. The suggestion for error handling could prevent crashes, but is it worth the added complexity for a developer-facing configuration value that rarely changes? While error handling would be more robust, the current behavior of crashing with ValueError is acceptable for a developer configuration. The stack trace would clearly show the issue. The comment should be deleted as it is partly informative (not actionable) and partly suggesting complexity that isn't clearly justified for this use case.
2. gptme/llm/llm_anthropic.py:488
  • Draft comment:
    The new _create_web_search_tool function is well implemented with proper parameters and return structure. It cleanly encapsulates the web search tool configuration.
  • Reason this comment was not posted:
    Comment did not seem useful. Confidence is useful = 0% <= threshold 50% This comment is purely informative and does not provide any actionable feedback or suggestions for improvement. It simply praises the implementation without offering any constructive criticism or questions.
3. gptme/llm/llm_anthropic.py:541
  • Draft comment:
    Integration of the native web search tool within _prepare_messages_for_api is clean. Duplicate prevention and error handling for invalid max_uses values are implemented nicely.
  • Reason this comment was not posted:
    Comment did not seem useful. Confidence is useful = 0% <= threshold 50% This comment is purely informative, as it only praises the integration and implementation without providing any actionable feedback or suggestions for improvement. It does not align with the rules for useful comments.
4. gptme/llm/llm_openai.py:77
  • Draft comment:
    Timeout configuration is updated to 600s by default and the comments now match client defaults. This ensures consistency with external client libraries.
  • Reason this comment was not posted:
    Comment did not seem useful. Confidence is useful = 0% <= threshold 50% This comment is purely informative, explaining a change that was made without suggesting any action or asking for clarification. It doesn't provide any actionable feedback or raise any concerns about the code.
5. tests/test_llm_anthropic.py:253
  • Draft comment:
    The tests for native web search functionality (enabled, disabled, invalid max_uses, duplicate prevention, and combination with other tools) are comprehensive and clearly validate the new behavior.
  • Reason this comment was not posted:
    Comment did not seem useful. Confidence is useful = 0% <= threshold 50% This comment is purely informative, as it praises the comprehensiveness of the tests without providing any actionable feedback or suggestions for improvement. It does not align with the rules for useful comments.
6. tests/test_llm_openai.py:275
  • Draft comment:
    Timeout tests correctly verify that the default (600s) and custom timeouts are applied across all providers, and that invalid values raise errors as expected.
  • Reason this comment was not posted:
    Comment did not seem useful. Confidence is useful = 0% <= threshold 50% This comment is purely informative, as it only states that the timeout tests are correctly verifying certain conditions. It does not provide any actionable feedback or suggestions for improvement.
7. gptme/llm/llm_openai.py:80
  • Draft comment:
    Suggestion: Since both Anthropic and OpenAI modules perform similar timeout conversion logic, consider centralizing this logic into a shared utility to reduce duplication and ease future maintenance.
  • Reason this comment was not posted:
    Comment was on unchanged code.

Workflow ID: wflow_ME9c5QVtpNttIaGD

You can customize Ellipsis by changing your verbosity settings, reacting with 👍 or 👎, replying to comments, or adding code review rules.

@codecov
Copy link
Copy Markdown

codecov Bot commented Oct 17, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ All tests successful. No failed tests found.

📢 Thoughts on this report? Let us know!

@TimeToBuildBob
Copy link
Copy Markdown
Member Author

Closing in favor of PR #735 which implements Erik's preferred approach.

Instead of explicitly setting timeout=600, PR #735 uses NOT_GIVEN to let the client use its own default behavior. This is cleaner and respects the client's handling of streaming vs non-streaming requests.

See Issue #732 for the full discussion.

@TimeToBuildBob TimeToBuildBob deleted the fix/issue-732-anthropic-timeout branch February 28, 2026 21:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Anthropic 5min default timeout is too high

2 participants