eca icon indicating copy to clipboard operation
eca copied to clipboard

streamIdleTimeoutSeconds and cacheRetention ignored for custom providers using Anthropic API

Open lockie opened this issue 6 months ago • 2 comments

To upvote this issue, give it a thumbs up. See this list for the most upvoted issues.

Describe the bug

streamIdleTimeoutSeconds and cacheRetention config values are only passed to the Anthropic LLM handler when the provider name is exactly "anthropic". Custom providers that specify "api": "anthropic" correctly resolve to llm-providers.anthropic/chat! via the fallback branch in provider->api-handler, but that branch does not forward these parameters. The watchdog then falls back to the hardcoded default of 120 seconds regardless of the configured value, and prompt caching always uses the short TTL.

To Reproduce

  1. Configure a custom provider with "api": "anthropic" and a custom URL:
    {
      "providers": {
        "my-proxy": {
          "api": "anthropic",
          "url": "https://my-proxy.example.com/v1",
          "key": "...",
          "models": { "claude-sonnet-4-6": {} }
        }
      },
      "defaultModel": "my-proxy/claude-sonnet-4-6",
      "streamIdleTimeoutSeconds": 600
    }
    
  2. Start a chat and trigger a long-running LLM response that stalls for >120s on a stream read.
  3. Observe: Stream idle timeout: no data received for 120 seconds — the configured 600s value is ignored.

Expected behavior

streamIdleTimeoutSeconds and cacheRetention should apply to any provider using the Anthropic API handler, not just the built-in "anthropic" provider.

Root cause

In src/eca/llm_api.clj, the prompt! function has separate cond branches for built-in providers and a fallback for custom providers. The built-in "anthropic" branch passes both params:

(= "anthropic" provider)
(handler
 {:model real-model
  ...
  :cache-retention (:cacheRetention provider-config)
  :stream-idle-timeout-seconds (:streamIdleTimeoutSeconds config)}
 callbacks)

The custom provider branch is missing both:

(and (or model-config model-capabilities) handler)
(handler
 {:model real-model
  ...
  :http-client http-client
  :api-url api-url
  :api-key api-key
  :cancelled? cancelled?}
 callbacks)

In src/eca/llm_providers/anthropic.clj, base-request! handles nil stream-idle-timeout-seconds by using the watchdog default (default-stream-idle-timeout-ms = 120000ms), and the error message format also falls back to 120 via (or stream-idle-timeout-seconds 120). For cache-retention, cache-control-value returns the default short TTL when nil, silently ignoring a user's "cacheRetention": "long" setting.

Fix

Add :stream-idle-timeout-seconds and :cache-retention to the custom provider branch's handler map in prompt!:

(and (or model-config model-capabilities) handler)
(let [url-relative-path (:completionUrlRelativePath provider-config)
      think-tag-start (:thinkTagStart provider-config)
      think-tag-end (:thinkTagEnd provider-config)
      http-client (:httpClient provider-config)]
  (handler
   {:model real-model
    ...
    :cancelled? cancelled?
    :stream-idle-timeout-seconds (:streamIdleTimeoutSeconds config)
    :cache-retention (:cacheRetention provider-config)}
   callbacks))

Doctor

ECA 0.135.2, Emacs eca plugin, Linux.

lockie avatar May 27 '26 10:05 lockie

Thanks! this should be fixed, available on the next release!

ericdallo avatar May 27 '26 18:05 ericdallo

Awesome, thanks!

lockie avatar May 27 '26 23:05 lockie