See the Rate Limit to understand the AfterShip rate limit policy.
The API returns its current rate limit status in the headers of every response, and the SDK exposes these headers on both successful responses and rate-limited errors, so you can monitor your consumption proactively instead of waiting for 429 errors.
Header
Description
X-RateLimit-Limit
The rate limit ceiling for the current endpoint per second
X-RateLimit-Remaining
The number of requests left for the 1-second window
X-RateLimit-Reset
The Unix timestamp when the rate limit will be reset
Every successful response exposes a response_header dict alongside data (header names are lower-cased, each value is a list of strings). Taking the Quick Start example above:
remaining = int(result.response_header["x-ratelimit-remaining"][0])
reset_at = int(result.response_header["x-ratelimit-reset"][0])
if remaining <= 1:
# Throttle or defer lower-priority requests until reset_at
pass
When the rate limit is exceeded, the request fails with a 429 error that carries the same headers — see Error Handling.
Error Handling
The SDK will return an error object when there is any error during the request, with the following specification:
Name
Type
Description
message
string
Detail message of the error
code
enum
Error code enum for API Error.
meta_code
number
API response meta code.
status_code
number
HTTP status code.
response_body
string
API response body.
response_header
object
API response header.
Error List
code
meta_code
status_code
message
INVALID_REQUEST
400
400
The request was invalid or cannot be otherwise served.
INVALID_JSON
4001
400
Invalid JSON data.
TRACKING_ALREADY_EXIST
4003
400
Tracking already exists.
TRACKING_DOES_NOT_EXIST
4004
404
Tracking does not exist.
TRACKING_NUMBER_INVALID
4005
400
The value of tracking_number is invalid.
TRACKING_REQUIRED
4006
400
tracking object is required.
TRACKING_NUMBER_REQUIRED
4007
400
tracking_number is required.
VALUE_INVALID
4008
400
The value of [field_name] is invalid.
VALUE_REQUIRED
4009
400
[field_name] is required.
SLUG_INVALID
4010
400
The value of slug is invalid.
MISSING_OR_INVALID_REQUIRED_FIELD
4011
400
Missing or invalid value of the required fields for this courier. Besides tracking_number, also required: [field_name]
BAD_COURIER
4012
400
The error message will be one of the following:1. Unable to import shipment as the carrier is not on your approved list for carrier auto-detection. Add the carrier here: https://admin.aftership.com/settings/couriers2. Unable to import shipment as we don't recognize the carrier from this tracking number.3. Unable to import shipment as the tracking number has an invalid format.4. Unable to import shipment as this carrier is no longer supported.5. Unable to import shipment as the tracking number does not belong to a carrier in that group.
INACTIVE_RETRACK_NOT_ALLOWED
4013
400
Retrack is not allowed. You can only retrack an inactive tracking.
NOTIFICATION_REQUIRED
4014
400
notification object is required.
ID_INVALID
4015
400
The value of id is invalid.
RETRACK_ONCE_ALLOWED
4016
400
Retrack is not allowed. You can only retrack each shipment once.
TRACKING_NUMBER_FORMAT_INVALID
4017
400
The format of tracking_number is invalid.
API_KEY_INVALID
401
401
The API Key is invalid.
REQUEST_NOT_ALLOWED
403
403
The request is understood, but it has been refused or access is not allowed.
NOT_FOUND
404
404
The URI requested is invalid or the resource requested does not exist.
TOO_MANY_REQUEST
429
429
You have exceeded the API call rate limit. The default limit is 10 requests per second.
INTERNAL_ERROR
500
500
Something went wrong on AfterShip's end.
INTERNAL_ERROR
502
502
Something went wrong on AfterShip's end.
INTERNAL_ERROR
503
503
Something went wrong on AfterShip's end.
INTERNAL_ERROR
504
504
Something went wrong on AfterShip's end.
Endpoints
The AfterShip instance has the following properties which are exactly the same as the API endpoints:
tracking
Get trackings
Create a tracking
Get a tracking by ID
Update a tracking by ID
Delete a tracking by ID
Retrack an expired tracking by ID
Mark tracking as completed by ID
courier
Get couriers
Detect courier
courier_connection
Get courier connections
Create courier connections
Get courier connection by id
Update courier connection by id
Delete courier connection by id
estimated_delivery_date
Prediction for the Estimated Delivery Date
Batch prediction for the Estimated Delivery Date
/trackings
GET /trackings
result = sdk.tracking.get_trackings(
)
print(result)
req = tracking.PredictBatchRequest()
result = sdk.estimated_delivery_date.predict_batch(
req,
)
print(result)
Help
If you get stuck, we're here to help:
Issue Tracker for questions, feature requests, bug reports and general discussion related to this package. Try searching before you create a new issue.