Ruby SDK · Feature

Errors, Rate Limits & Usage

Errors are raised as typed exceptions and the client never retries — you stay in control of back-off. It also exposes your current quota so you can throttle before you hit a limit, and aggregate usage for dashboards and alerts.

Trusted by thousands of businesses
Fast JSON API responses
Real-time validation
Simple integration, SDKs & examples
What it does

Predictable failures, no hidden retries

Network calls fail — keys expire, quotas run out, servers hiccup. The SDK turns each HTTP status into a specific exception class you can rescue, and deliberately leaves retry policy to you, so a burst of failures can't silently multiply your request volume. When you do hit a rate limit, the error tells you exactly when the quota resets.

Prerequisites

1

Rescue typed exceptions

Every typed error inherits from Ipapi::Error and carries #status_code, #message and #body. Rescue the specific class you care about.

begin
  info = client.lookup_ip("8.8.8.8")
  puts info.ip
rescue Ipapi::RateLimitError => e
  puts "quota hit — resets at #{e.reset}"
rescue Ipapi::AuthenticationError
  puts "check your API key"
rescue Ipapi::InvalidRequestError => e
  puts "bad request: #{e.message}"
rescue Ipapi::ServerError
  puts "ip-api.io is having trouble, try later"
rescue Ipapi::Error => e
  puts "transport / decode error: #{e.message}"
end
Transport failures (DNS, connect, timeout, parse) are raised as the base Ipapi::Error — they are caught by the final rescue above.
2

Handle rate limits with RateLimitError

On HTTP 429 you get Ipapi::RateLimitError, carrying the x-ratelimit-* header values (-1 when a header is absent). Because the client never retries, #reset tells you when to.

rescue Ipapi::RateLimitError => e
  puts e.limit     # your quota for the window
  puts e.remaining # requests left (0 here)
  puts e.reset     # unix timestamp when quota renews
  # schedule a retry at e.reset instead of hammering the API
3

Check quota proactively with rate_limit

Read your current limits without triggering a 429, so you can throttle in advance.

rl = client.rate_limit

puts rl.plan_name
puts "#{rl.ip_api.remaining} / #{rl.ip_api.limit}"
puts "#{rl.email_api.usage_percent}% used"
4

Account usage with usage_summary

Aggregate usage for the current period — handy for dashboards and internal alerts.

usage = client.usage_summary

puts "#{usage.total_requests} #{usage.successful_requests}"
puts "#{usage.rate_limited_requests} #{usage.quota_consumed}"
puts "#{usage.period_start} #{usage.period_end}"
Reference

Error taxonomy

ClassHTTP statusMeaning
Ipapi::AuthenticationError401, 403Missing or invalid API key
Ipapi::RateLimitError429Quota exhausted; exposes #limit, #remaining, #reset
Ipapi::InvalidRequestError400, 404, 422Malformed input or unknown resource
Ipapi::ServerError5xxip-api.io server-side failure
Ipapi::ErrorotherBase / fallback (carries #status_code, #message, #body)
FAQ

Frequently asked questions

How do I handle errors from the ip-api.io SDK in Ruby?

Errors are raised as exceptions. Rescue the specific subclass: Ipapi::AuthenticationError (401/403), Ipapi::RateLimitError (429), Ipapi::InvalidRequestError (400/404/422), Ipapi::ServerError (5xx), or the base Ipapi::Error for everything else including transport failures.

Does the SDK retry failed requests automatically?

No. The client never retries — you stay in control of back-off. On a 429, RateLimitError#reset gives the unix timestamp when your quota renews, so you can schedule a retry instead of hammering the API.

How do I check my remaining quota before hitting a limit?

Call client.rate_limit. It returns plan_id, plan_name, and ip_api / email_api blocks with limit, remaining, used and usage_percent, plus interval_seconds and next_renewal_date.

What does RateLimitError expose?

Ipapi::RateLimitError is parsed from the x-ratelimit-* response headers and exposes #limit (quota for the window), #remaining (requests left), and #reset (unix timestamp when quota renews). Headers absent? The value is -1.

Start building with the ip-api.io Ruby SDK

Run gem install ip-api-io, drop in your free API key, and ship in minutes — one client object for geolocation, fraud detection, and email validation.

Need support?

Explore how IP-API.io can enhance your security, provide robust bot protection, and improve IP geolocation accuracy for your applications.

Contact Support

Found a bug in the SDK?

The ip-api-io gem is open source. Open an issue or pull request on GitHub and we'll take a look.

Open on GitHub