ChannelDocsOpen workspace ↗

Cookbook

Match one answer to a charge

After a successful chat response, retain the receipt and fetch the statement using the same client key. The following Python fragment follows the quickstart and uses its existing imports and data variable.

receipt = data["channel"]
req = Request("https://app.westernrose.uk/v1/statement", headers={
    "Authorization": "Bearer " + os.environ["CHANNEL_API_KEY"],
    "User-Agent": "Channel-Quickstart/1.0"})
with urlopen(req, timeout=90) as response:
    statement = json.load(response)
row = next(r for r in statement["requests"] if r["request"] == receipt["request"])
for field in ("micro_gbp", "usd_nano", "micro_eur"):
    assert row[field] == receipt[field], field

Convert amounts for display

For new receipts, divide usd_nano by 10⁹ and both micro_gbp and micro_eur by 10⁶. Preserve the integers for comparisons. EUR is a reference equivalent at settlement. An older row can have null EUR fields; display “unavailable” rather than substituting today’s FX.

Allocate monthly client costs

Sum settled GBP amounts for the relevant UTC month. Group by client before rounding to display precision. Show the fee paid on the funding receipt separately. For £20 of credit, a 4.5% top-up fee is £0.90 and the card total would be £20.90. Request-level usage spends the £20 credit.

Diagnose a rejected integration

A 400 usually means the model ID or message shape needs attention. A 401 calls for checking the client credential; a 403 can also originate at the edge before the gateway returns JSON. A 402 concerns the workspace’s available credit. For a 502, preserve the request ID for investigation. A client workspace balance and a provider’s upstream balance are separate.