Rate Limits
Understanding user limits for API calls.
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:
- The SDK will handle rate limiting automatically unless this feature is disabled by the user. When a limit is hit, it will sleep until the appropriate time and then retry the request.
- Non-SDK users will receive a 429 HTTP status code if the limit is reached. Retries must be handled manually by the user in this setting.
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)
If you disable automatic handling, you will receive a 429 HTTP status code in the header containing the retry-after value (for example, "Rate limit exceeded: 10 requests per 1 minute").
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.
This example is for the
structure
endpoint. For help structuring your code for other endpoints, see Call a Different Endpoint
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."}'
Updated 3 days ago