Rate Limiters

Rate limiters allow you to control the rate at which Taskhook executes callbacks for your tasks. Use rate limiters to ensure you respect 3rd party API rate limits, manage resource utilization, or control the flow of webhook executions. Rate limiters don't limit the rate at which you can call Taskhook APIs.

Understanding rate limiters

Rate limiters provide several key capabilities:

  • Define rate limiting rules that can be applied to any task
  • Support various rate limiting algorithms for different use cases
  • Apply rate limits across all your tasks, schedules, and batches
  • Monitor rate limit usage and receive notifications
  • Dynamically adjust limits as needed

POST/v1/rate-limiters

Create a rate limiter

This endpoint creates a new rate limiter that can be referenced in your tasks, schedules, and batches.

Required attributes

  • Name
    name
    Type
    string
    Description

    Unique identifier for referencing this rate limiter (letters, numbers, hyphens only).

  • Name
    type
    Type
    string
    Description

    The type of rate limiter: concurrent, bucket, window, leaky, or points

  • Name
    config
    Type
    object
    Description

    Configuration specific to the chosen rate limiter type

Optional attributes

  • Name
    description
    Type
    string
    Description

    Human-readable description of the rate limiter's purpose

  • Name
    timeouts
    Type
    object
    Description

    Configure queueing behavior:

    • queue_timeout: Maximum time in seconds to queue a task (default: 300)
    • validity_timeout: Time in seconds after which queued tasks expire (default: 3600)

Request

POST
/v1/rate-limiters
curl https://api.taskhook.io/v1/rate-limiters \
  -H "Authorization: Bearer {token}" \
  -d '{
    "name": "stripe-api",
    "type": "window",
    "description": "Rate limit for Stripe API calls",
    "config": {
      "limit": 100,
      "interval": 60
    },
    "timeouts": {
      "queue_timeout": 300,
      "validity_timeout": 3600
    }
  }'

Response

{
  "id": "rl_123abc",
  "name": "stripe-api",
  "type": "window",
  "description": "Rate limit for Stripe API calls",
  "config": {
    "limit": 100,
    "interval": 60
  },
  "timeouts": {
    "queue_timeout": 300,
    "validity_timeout": 3600
  },
  "created_at": "2024-01-30T12:00:00Z",
  "updated_at": "2024-01-30T12:00:00Z"
}

GET/v1/rate-limiters/:id

Get a rate limiter

Retrieve details of a specific rate limiter by its ID.

Required parameters

  • Name
    id
    Type
    string
    Description

    The unique identifier of the rate limiter to retrieve

Request

GET
/v1/rate-limiters/rl_123abc
curl https://api.taskhook.io/v1/rate-limiters/rl_123abc \
  -H "Authorization: Bearer {token}"

Response

{
  "id": "rl_123abc",
  "name": "stripe-api",
  "type": "window",
  "description": "Rate limit for Stripe API calls",
  "config": {
    "limit": 100,
    "interval": 60
  },
  "timeouts": {
    "queue_timeout": 300,
    "validity_timeout": 3600
  },
  "created_at": "2024-01-30T12:00:00Z",
  "updated_at": "2024-01-30T12:00:00Z"
}

GET/v1/rate-limiters

List rate limiters

Retrieve a paginated list of your rate limiters.

Optional attributes

  • Name
    limit
    Type
    integer
    Description

    Maximum number of rate limiters to return (default: 100)

  • Name
    offset
    Type
    integer
    Description

    Number of rate limiters to skip (default: 0)

Request

GET
/v1/rate-limiters
curl -G https://api.taskhook.io/v1/rate-limiters \
  -H "Authorization: Bearer {token}" \
  -d limit=10

Response

{
  "total": 2,
  "rate_limiters": [
    {
      "id": "rl_123abc",
      "name": "stripe-api",
      "type": "window",
      "config": {
        "limit": 100,
        "interval": 60
      },
      "created_at": "2024-01-30T12:00:00Z"
    },
    {
      "id": "rl_456def",
      "name": "shopify-api",
      "type": "leaky",
      "config": {
        "capacity": 100,
        "drain_rate": 10,
        "interval": 1
      },
      "created_at": "2024-01-30T12:00:00Z"
    }
  ]
}

PATCH/v1/rate-limiters/:id

Update a rate limiter

Update an existing rate limiter's configuration.

Required parameters

  • Name
    id
    Type
    string
    Description

    The unique identifier of the rate limiter to update

Optional attributes

  • Name
    description
    Type
    string
    Description

    Updated description for the rate limiter

  • Name
    config
    Type
    object
    Description

    Updated configuration for the rate limiter

  • Name
    timeouts
    Type
    object
    Description

    Updated timeout configuration

Request

PATCH
/v1/rate-limiters/rl_123abc
curl -X PATCH https://api.taskhook.io/v1/rate-limiters/rl_123abc \
  -H "Authorization: Bearer {token}" \
  -d '{
    "description": "Updated rate limit for Stripe API",
    "config": {
      "limit": 150,
      "interval": 60
    }
  }'

Response

{
  "id": "rl_123abc",
  "name": "stripe-api",
  "type": "window",
  "description": "Updated rate limit for Stripe API",
  "config": {
    "limit": 150,
    "interval": 60
  },
  "timeouts": {
    "queue_timeout": 300,
    "validity_timeout": 3600
  },
  "created_at": "2024-01-30T12:00:00Z",
  "updated_at": "2024-01-30T12:30:00Z"
}

DELETE/v1/rate-limiters/:id

Delete a rate limiter

Delete a rate limiter. This action cannot be undone.

Required parameters

  • Name
    id
    Type
    string
    Description

    The unique identifier of the rate limiter to delete

Request

DELETE
/v1/rate-limiters/rl_123abc
curl -X DELETE https://api.taskhook.io/v1/rate-limiters/rl_123abc \
  -H "Authorization: Bearer {token}"

Response

{
  "deleted": true,
  "id": "rl_123abc"
}

Using rate limiters

To apply a rate limiter to tasks, reference it by name in your task creation:

{
  "target": "https://api.stripe.com/v1/charges",
  "rate_limiter": "stripe-api",
  "execute_after": "2024-02-01T00:00:00Z",
  "valid_until": "2024-02-01T01:00:00Z",
  ...
}

For schedules and batches, include it in the task template:

{
  "task_template": {
    "target": "https://api.stripe.com/v1/charges",
    "rate_limiter": "stripe-api",
    ...
  }
}

When using points-based rate limiting, you can specify the cost per task:

{
  "target": "https://api.github.com/graphql",
  "rate_limiter": "github-api",
  "points_cost": 5,
  ...
}

Best practices

  1. Naming conventions: Use descriptive names that identify the API or resource being rate limited (e.g., "stripe-api", "github-graphql").

  2. Timeout configuration:

    • Set queue_timeout based on your application's latency requirements
    • Set validity_timeout to prevent execution of stale tasks
    • Consider downstream API timeout configurations
  3. Rate limit selection:

    • Use concurrent for strict parallel operation limits
    • Use window for standard API rate limits
    • Use leaky bucket when bursting is acceptable
    • Use points for complex API quotas
  4. Monitoring: Monitor rate limiter metrics to adjust configurations:

    • Queue depth and wait times
    • Task expiration rates
    • Rate limit utilization

Limitations

  • Names must be unique within your account
  • Names can only contain letters, numbers, and hyphens
  • Certain rate limiter types may not be available on all plans

Rate limiter deletion

When a rate limiter is deleted:

  • Queued tasks using the limiter will execute without rate limiting
  • New tasks cannot be created referencing the deleted limiter
  • Historical data is retained for 30 days

Was this page helpful?