You’ll be talking to the sandbox: the gateway responds with the simulated engine, deterministically and with no real money. You need a sandbox key and the SDK installed. Pick your language in any tab: your choice is remembered across the whole site.

1. Set up the key #

Store the key in an environment variable; every example reads it from there.

Shell
export COMPENSE_API_KEY="cmp_..."        # PowerShell: $env:COMPENSE_API_KEY = "cmp_..."

2. Create the client and validate the key #

system.health doesn’t touch the engine: it confirms the key is valid and returns the tenant it belongs to and its scopes. It’s the first call of any integration (and a good health check for your monitoring).

import os
from compense_gateway import CompenseClient

client = CompenseClient(api_key=os.environ["COMPENSE_API_KEY"], environment="sandbox")

health = client.system.health()
print(health.status, health.tenant, health.scopes)
# ok horizonte ['affiliates:read', 'credits:submit', ...]

If you see a 401, the header is missing; a 403 means the key is invalid, revoked, from another environment or missing the scope. See Authentication.

3. Look up an affiliate #

affiliates.get matches a document against your entity’s affiliate registry. This lookup isn’t simulated: it reads the affiliates your entity has already loaded (through the dashboard or with affiliates.cross). Use a document from your own base; one that isn’t there responds 404, and each SDK turns it into its “not found” exception.

from compense_gateway import NotFoundError

try:
    lookup = client.affiliates.get("1032456789")
    print(lookup.exists, lookup.affiliate.get("category"))
except NotFoundError as e:
    print("Not an affiliate:", e.status, e.trace_id)

4. Submit a credit application (your first write) #

Credits are simulated in the sandbox, with documents that have fixed behavior: CC 1000000001 is eligible (approved and disbursable), 1000000002 is ineligible, 1000000003 goes to manual review and 9999999999 doesn’t exist. The full table is in Test data.

Every write carries an Idempotency-Key: if the request gets cut off and you resend it with the same key, the gateway returns the original response instead of submitting twice. The SDKs generate one automatically, but when you control the retries it’s best to give it a stable one per business operation (for example, derived from your application number). More in Idempotency.

tx = client.credits.submit_application(
    affiliate={"document_type": "CC", "document_number": "1000000001"},
    product_code="LIBRANZA_12M",
    amount="3500000",               # amounts as decimal strings
    term_months=12,
    external_reference="HORIZONTE-CRED-2026-000123",
    idempotency_key="horizonte-cred-2026-000123",
)
print(tx.transaction_id, tx.status, tx.idempotent_replay)
print(tx.data)                      # engine body: application id, status…

The response to every write is the transaction envelope:

JSON
{
  "status": "success",
  "transaction_id": "a1b2c3d4-0000-4a1b-9c2d-000000000001",
  "module": "credits",
  "data": { "application_id": "sbx-…", "module": "credits", "status": "RECEIVED", "profile": "eligible", "environment": "sandbox" }
}

Run the same code again: you’ll see the same transaction_id and idempotent_replay: true. That’s the guarantee that lets you retry without fear of duplicates.

5. Check the transaction status #

Store the transaction_id in your system: it’s the reference for support and for reconciliation.

status = client.transactions.get(tx.transaction_id)
print(status.module, status.status, status.history)

What’s next #