Guides

Handling Requests

Overview

Regardless of which technical approach you're using, you'll need to implement appropriate logic for processing both successful and failed responses from your GenAI requests. This section focuses on understanding these responses and implementing robust handling for all scenarios.

While handling the basic provider responses is required, handling the Pay-i specific objects (xproxy_result for successful responses and xproxy_error for errors) is optional and only necessary if you want to implement business logic that depends on the metrics provided by Pay-i. The availability of these objects varies based on your integration method, as detailed in the following guides.

Handling Successful Requests

Handling Successful Requests covers how to work with the xproxy_result object that's returned when requests complete successfully. This guide explains:

  • Where the xproxy_result object appears in different contexts (Proxy Routing vs. Direct Provider Call with Telemetry, and streaming vs. synchronous requests)
  • How to interpret cost and limit information contained in the result
  • The structure differences between successful and failed requests
  • Examples of successful request responses with detailed explanation

The xproxy_result object provides essential information about your request's execution, including cost calculations and limit status.

Learn more in the Handling Successful Requests guide.

Handling Failed Requests

Handling Errors explains the structure of error responses when Pay-i returns HTTP 4xx status codes. This guide covers:

  • The standard error response properties (statusCode and message)
  • The optional xproxy_error and xproxy_result properties
  • How these properties help diagnose different types of failures
  • Examples of error responses with detailed explanation
  • How Provider errors are combined with Pay-i's error information

Understanding these error structures is essential for implementing robust error handling in your application.

Learn more in the Handling Errors guide.

Best Practices

When implementing request handling with Pay-i:

  • Always implement proper error handling with appropriate fallbacks
  • Consider both GenAI provider errors and Pay-i-specific errors
  • For production applications, implement retry logic with exponential backoff
  • Monitor error rates to identify potential issues early
  • Use Limit Details to handle budget/limit-related responses

By understanding both successful and error response handling, you'll create more robust GenAI applications that can gracefully handle the various conditions that arise in production environments.