Rate Limits

The following rate limits are in place for all ScienceIO accounts:

  • Users may make up to 10 API calls (or POST requests) every 1 minute.
  • Users may make up to 300 GET requests every 1 minute.
  • Users will be rate limited when they exceed either of these caps.

In addition:

Remember that the API can only accept a maximum of 10,000 characters per API call.

Disable Automatic Retries (Python SDK)

You may disable automatic retries when the rate limit is hit by using the following code:

# Import the HTTP Status library
from http import HTTPStatus
# Import time functions
import time

from scienceio import ScienceIO, HTTPError
scio = ScienceIO(enable_rate_limit_retry=False)

query_text = "ALS is often called Lou Gehrig's disease, after the baseball player who was diagnosed with it. Doctors usually do not know why ALS occurs."

try:
    response = scio.structure(query_text)
except HTTPError as e:
    # Retry time is based on the response.headers value
    # Max retry time is 60 seconds
    if e.status_code == HTTPStatus.TOO_MANY_REQUESTS:
        retry_after = int(e.headers.get('retry-after', 0)) 
        time.sleep(retry_after)
        response = scio.structure(query_text)

print(response)

Retry Manually (HTTP)

If you hit the rate limit, add verbose to your code as shown below. This will enable you to access the retry-after header, which contains the number of seconds you must wait to try your call again. Learn more about the Retry-After header here.

Remember that the retry-after value can be accessed at any time, so you should wait to retrieve this value after you have received a 429 error; this value is not applicable unless an error has occurred.

curl https://api.aws.science.io/v2/structure \
  --request POST \
  --verbose \
  --header "Content-type: application/json" \
  --header "x-api-id: $SCIENCEIO_KEY_ID" \
  --header "x-api-secret: $SCIENCEIO_KEY_SECRET" \
  --data '{ "text": "ALS is often called Lou Gehrigs disease, after the baseball player who was diagnosed with it. Doctors usually do not know why ALS occurs."}'