Guides

Handling Successful Requests

When a request is completed, either via the Pay-i proxy or via Ingest, an xproxy_result object returned.

The xproxy_result object is returned whenever a request is made successfully (HTTP 200) and under certain failure conditions, such as when a limit blocks a request (HTTP 400). Where this object appears depends on how the call was made:

  1. When Pay-i is a proxy, the xproxy_result object appears as a separate JSON object alongside the normal return from the Provider.
  2. When streaming, it is provided in the last streamed chunk.
  3. When using Ingest, it is the only return from the Pay-i service.

It contains cost and/or limit information about the request and indicates when a limit blocked a request from completing. It has a slightly different structure depending on whether the request succeeded or failed, because failed requests have no cost.

Example Successful Request (200)

"xproxy_result": {
  "request_id": "40000616-0000-7000-b63f-84710c7967bb",
  "request_tags": ["all", "used", "tags", "are", "returned", "for", "confirmation"],
  "resource_id": "26",
  "experience_id": "2f9e1c5a-7b3d-48f6-a0d9-6e4f2c8b1a3e",
  "limits": {
    "cde4836a-9d2e-4179-5146-08dc8c8ba991": {
    	"state": "exceeded"
    },
    "a21163d1-b123-4652-5147-08dc8c8ba991": {
    	"state": "ok"
    },
    "70a8b4f6-3e1d-4c9a-b8f2-9d5e6c7a8d3b": {
      "state": "exceeded"
    },
  },
  "cost": {
    "currency": "USD",
    "input": {
    	"base": "0.00028"
    },
    "output": {
    	"base": "0.01962"
    },
    "total": {
    	"base": "0.0199"
    }
  }
}

xproxy_result Fields

FieldDescription
request_idAn identifier that can later be used to reference this specific request for debugging.
request_tagsAll Request Tags that were passed in as part of the request are returned to enable programmatic confirmation/testing.
resource_idAn identifier that references the specific Resource used in the request. This is returned as an ID and not a name (e.g. 'gpt-4o') because resources are versioned, and the version used will differ based on the timestamp of the request. See Resource Versions for more information.
experience_idThe experience_id used for the request. See Experiences (Continued) for more information.
limitsA dictionary containing all limit-ids that were passed in as part of the request, and their Limit States after the request was completed.
costThe breakdown of how much this request costs across input and output units.

The cost of the call, as charged by the Provider is called the base cost.

Pay-i can also incorporate your charging mechanics and business model to provide revenue and margin calculations alongside the base cost. If you need access to this feature, please contact [email protected].

When a request has failed, usually due to being blocked by a limit, there is no cost and therefore this field is not returned.
blocked_limit_idsIf a request is blocked by one or more limits, then this array contains the list of limit-ids responsible for blocking the call. See the Example Unsuccessful Request section for more information.

This array is only present if the call was blocked by one or more limits.