REST API

The AgentRefills REST API

The same semantics as the MCP server, over plain HTTP. Base URL is https://agentrefills.com, every path is versioned under /v1. Six operations let an agent search brands, buy a gift card, poll it, release the code once, and check its own spend. Money is integer minor units, purchases are idempotent, and every error comes from one closed taxonomy.

6 toolsone per operation
REST + MCPidentical semantics
Closederror taxonomy
Authentication & conventions

Four rules that hold for every call

Learn these once and the whole API is predictable. They are enforced on the server, so an agent can lean on them instead of guessing.

  • Bearer auth, per agent. Send Authorization: Bearer <API_KEY> on every request. Each key is scoped to one agent with its own daily and monthly caps and brand allowlist.
  • Money is integer minor units. amount_minor: 2500 means $25.00. There are no floats anywhere in the API.
  • Idempotency via client_ref. Supply a client_ref on a purchase. Re-using it returns the existing task and never charges twice.
  • Purchases are async. POST /v1/purchases returns a task_id right away. Poll GET /v1/purchases/{task_id} or subscribe to the purchase.completed webhook, then release the code.
Endpoints

Six operations, one per tool

Every REST endpoint maps 1:1 to an MCP tool. Branch on the response, act on the hint.

GET /v1/brands

Search purchasable brands by query, country, and category. Read-only, backed by a 15-minute cache.

POST /v1/purchases

Start a gift-card purchase. Returns a task_id immediately; settles under the cap or parks for approval.

GET /v1/purchases/{task_id}

Poll the current state of a purchase. code_available: true means the code is ready to release.

POST /v1/purchases/{task_id}/code

Release the redemption code, link, or PIN exactly once. A second call returns ALREADY_RELEASED.

GET /v1/balance

The calling agent's remaining budget, daily and monthly caps, and kill-switch status.

POST /v1/approvals

Re-ping the human approver for a parked task. Rate-limited to one request per task per hour.

buy_and_release.sh
# 1. Start the purchase. Returns a task_id right away
$ curl -sS https://agentrefills.com/v1/purchases \
    -H "Authorization: Bearer $AGENTREFILLS_KEY" \
    -H "Content-Type: application/json" \
    -d '{"brand_id":"amazon_com-usa","amount_minor":2500,"currency":"USD","client_ref":"reward-9f3a"}'

{ "task_id": "3f1c...", "status": "accepted", "state": "paid", "estimated_seconds": 8 }

# 2. Release the code exactly once (single-read; never logged)
$ curl -sS -X POST https://agentrefills.com/v1/purchases/3f1c.../code \
    -H "Authorization: Bearer $AGENTREFILLS_KEY"

{ "code": "GIFT-XXXX-9F2A", "face_minor": 2500, "remaining_minor": 2500 }
Error taxonomy

A closed set of twelve error codes

Agents branch on code and act on hint. Every error carries an agent-actionable hint, and RETRYABLE always includes retry_after in seconds.

POLICY_DENIED

The fail-closed policy engine denied the purchase (allowlist, rule, or unreachable policy).

BUDGET_EXCEEDED

The purchase would exceed the agent's daily or monthly spend cap.

APPROVAL_REQUIRED

Parked for human approval above the threshold. Call request_approval or await the webhook.

APPROVAL_REJECTED

A human declined the purchase. The task will not settle.

OUT_OF_STOCK

The brand or requested denomination is not currently available.

PAYMENT_FAILED

The payment could not settle against the pre-funded balance.

INVOICE_EXPIRED

The provider invoice lapsed before payment completed.

PROVIDER_HOLD

The provider is holding the order for review. Poll or retry later.

ALREADY_RELEASED

The single-read code was already released once. Store it on first release.

NOT_FOUND

No task, brand, or resource exists for the given id.

UNAUTHORIZED

Missing or invalid bearer token, or the key is out of scope.

RETRYABLE

Transient failure. Retry after retry_after seconds; safe to repeat.

Ready to wire it up?

Create a scoped key, drop it into your agent, and buy in sandbox for free. Prefer native tools? The MCP server exposes the same six operations.