Skip to content

rate limit handling on endpoints #42

@kwypchlo

Description

@kwypchlo

Currently rate limited requests return these headers from coingecko api

< x-ratelimit-limit: 30
< x-ratelimit-remaining: 0
< x-ratelimit-reset: 2025-07-25 14:54:00 +0000

but sdk only supports handling retry-after-ms and retry-after

    // Note the `retry-after-ms` header may not be standard, but is a good idea and we'd like proactive support for it.
    const retryAfterMillisHeader = responseHeaders?.get('retry-after-ms');
    if (retryAfterMillisHeader) {
      const timeoutMs = parseFloat(retryAfterMillisHeader);
      if (!Number.isNaN(timeoutMs)) {
        timeoutMillis = timeoutMs;
      }
    }

    // About the Retry-After header: https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Retry-After
    const retryAfterHeader = responseHeaders?.get('retry-after');
    if (retryAfterHeader && !timeoutMillis) {
      const timeoutSeconds = parseFloat(retryAfterHeader);
      if (!Number.isNaN(timeoutSeconds)) {
        timeoutMillis = timeoutSeconds * 1000;
      } else {
        timeoutMillis = Date.parse(retryAfterHeader) - Date.now();
      }
    }

Solutions

  1. ping method should return 'retry-after' header
  2. coingecko api could calculate 'retry-after-ms' based on delta between now and x-ratelimit-reset and include 'retry-after-ms' header
  3. sdk could include handling 'x-ratelimit-reset' header (not sure if that's easy with stainless 🤷 )

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions