Rate Limits | Clarifai Docs

Learn about our API rate limits

Our API has restrictions that limit the rate at which requests are made. These measures help us maintain the health, fairness, and security of our API.

Our default rate limit is 15 requests per second for all users, regardless of the pricing plan. You need to contact us if you need a customized API rate limit.

We control the number of requests that can be made to our API within a given timeframe.

This helps to:

Mitigating Rate Limits

You may bump into the API rate limit if you make requests exceeding your quota within the specified time frame. When the limit is reached, the API temporarily halts processing additional requests until a designated time interval has elapsed.

The error response could look like this:

{
  "status": {
    "code": "CONN_THROTTLED",
    "description": "Making too many requests",
    "details": "exceeded limit of 15 requests per second",
    "req_id": "..."
  },
  ...
}

As you can see above, the response includes the CONN_THROTTLED error, whose corresponding status code is 11005.

It’s a best practice to mitigate the rate limit errors in your code to ensure smooth access to the Clarifai API. For example, you can implement a back-off strategy, where you wait for 15 seconds before retrying the requests.

Here are HTTP-based code samples on how you could list Clarifai's model types and also handle rate limit errors.

Python

import requests
import time

def make_request(url, headers):
    try:
        response = requests.get(url, headers=headers)
        response.raise_for_status()
        return response.json()
    except requests.exceptions.HTTPError as err:
        error_response = err.response.json()
        if (
            "status" in error_response
            and error_response["status"]["code"] == "CONN_THROTTLED"
        ):
            print("Rate limit exceeded. Waiting for 15 seconds before retrying...")
            time.sleep(15)
            return make_request(url, headers)  # Retry the request after waiting
        else:
            # Handle other types of errors
            print("Error:", err)
            return None

url = "https://api.clarifai.com/v2/models/types"
headers = {"Authorization": "Key YOUR_PAT_HERE"}

response_data = make_request(url, headers)

if response_data:
    print(response_data)

JavaScript

const axios = require('axios');
async function makeRequest(url, headers) {
    try {
        const response = await axios.get(url, { headers });
        return response.data;
    } catch (error) {
        if (error.response && error.response.data.status && error.response.data.status.code === 'CONN_THROTTLED') {
            console.log("Rate limit exceeded. Waiting for 15 seconds before retrying...");
            await delay(15000); // Wait for 15 seconds before retrying
            return makeRequest(url, headers); // Retry the request after waiting
        } else {
            // Handle other types of errors
            console.error("Error:", error);
            return null;
        }
    }
}
// Helper function to delay execution
function delay(ms) {
    return new Promise(resolve => setTimeout(resolve, ms));
}
const url = "https://api.clarifai.com/v2/models/types";
const headers = { 'Authorization': 'Key YOUR_PAT_HERE' };
makeRequest(url, headers)
    .then(responseData => {
        if (responseData) {
            console.log(responseData);
        }
    });

Build your next AI app, test and tune popular LLMs models, and much more.