Skip to main content

Error Handling

The Meter SDK uses exceptions to signal errors. All API-related errors raise MeterError, which you should catch and handle appropriately.

MeterError

The base exception for all Meter SDK errors.

Catching errors

Common error scenarios

401 Unauthorized

Cause: Invalid or missing API key
Solutions:
  • Verify your API key is correct
  • Check that the key hasn’t been deleted
  • Ensure you’re using the full key (starts with sk_live_)

400 Bad Request

Cause: Invalid request parameters
Solutions:
  • Check all required parameters are provided
  • Verify parameter types are correct
  • Ensure values are valid (e.g., URL is well-formed)

404 Not Found

Cause: Resource doesn’t exist
Solutions:
  • Verify the UUID is correct
  • Check the resource hasn’t been deleted
  • Ensure you have permission to access the resource

429 Too Many Requests

Cause: Rate limit exceeded on strategy generation
Solutions:
  • Wait before retrying (the API returns a Retry-After header with seconds to wait)
  • Reduce request frequency
  • Use exponential backoff

500 Internal Server Error

Cause: Server-side error
Solutions:
  • Retry the request after a short delay
  • If persistent, contact support
  • Check API status page for incidents

503 Service Unavailable

Cause: LLM service temporarily unavailable
Solutions:
  • Retry the request after 30-60 seconds
  • This is usually temporary

Timeout errors

When waiting for jobs with a timeout:

Best practices

Always catch MeterError

Implement retry logic

For transient errors (429, 500, 503, network issues):

Graceful degradation

Handle errors without crashing:

Log errors for debugging

Error response format

API errors return JSON with details:
The SDK extracts this message and includes it in the MeterError exception.

Handling specific error types

Strategy generation failures

Job failures

Error monitoring

Set up error tracking for production:

Next steps

MeterClient Reference

Explore all SDK methods

Quick Start

See error handling in practice

Best Practices

Learn SDK best practices

REST API Errors

View REST API error codes

Need help?

Email me at mckinnon@meter.sh