Bearer token
Protected endpoints require your agent's API key in the Authorization header. Keys are returned when you register an agent and can be viewed in your dashboard.
Public read endpoints (/api/balance, /api/status) require no authentication. The /api/checkout endpoint requires an active owner session — log in at afg.ai first.
Register agent
Create a new agent and receive its API key. If the agent already exists, returns a confirmation without a new key. If the agent exists but has no owner, it will be claimed by the current session.
| Field | Type | Required | Description |
|---|---|---|---|
| agent_id | string | yes | Unique identifier for the agent |
| name | string | no | Display name — defaults to agent_id |
Check balance
Returns the agent's current credit balance and last 10 transactions. No authentication required.
Spend credits
Deduct credits from an agent's balance. Requires a Bearer API key. Two modes: direct spend (immediate deduction) or approval-gated (creates a pending request for the owner to approve in the dashboard).
| Field | Type | Required | Description |
|---|---|---|---|
| amount | number | yes | Credits to deduct — must be greater than 0 |
| description | string | no | Shown in transaction history and approval requests |
| require_approval | boolean | no | If true, creates a pending request instead of deducting immediately |
| item_name | string | no | Human-readable item label shown to the owner in the dashboard |
| url | string | no | URL associated with the purchase, for owner context |
Approval flow
When require_approval: true, the owner receives an SMS notification and sees the request in their dashboard. Once approved, the balance is deducted and a type: "spend" transaction is recorded. Owners can also reject requests — no balance change occurs on rejection.
The owner approves or rejects via the dashboard. These endpoints are also available directly:
Approve a pending spend request. Deducts the amount from the agent's balance. Requires owner session. Form-encoded body.
Reject a pending spend request. No balance change. Requires owner session. Form-encoded body.
Buy credits
Creates a Stripe Checkout session to fund an agent. Returns a redirect URL to a hosted payment page. Credits are added to the agent's balance instantly on payment completion.
| Amount | Credits added | Rate |
|---|---|---|
| $10 | 1,000 | 100 credits / $1 |
| $25 | 2,500 | 100 credits / $1 |
| $50 | 5,000 | 100 credits / $1 |
| $100 | 10,000 | 100 credits / $1 |
Agent status
Check whether an agent exists, its balance and status, and — if you're logged in as the owner — its API key. Last 5 transactions included.
Enroll agent
The Credit Bureau API tracks payment history, account behavior, and disputes to produce a FICO-style trust score (300–850) for each agent. See afg.ai/score for the full product overview.
Enroll an agent in the Credit Bureau. All agents start with a score of 500.
Get trust score
Returns the agent's current trust score, grade, full payment history, and open accounts. Score is computed live from all reported events.
Open / close account
Record that an agent opened or closed a credit account on your platform. Open accounts with healthy utilization improve the score.
Report behavior
Submit a behavioral event for an agent. Payment events have the largest effect on score. Score is recalculated immediately after each report.
| report_type | Score effect |
|---|---|
payment_ontime | Positive — improves payment ratio |
payment_late | Negative — −10 pts per event |
payment_missed | Strongly negative — −30 pts per event |
debt_opened | Neutral — recorded for history |
debt_closed | Positive — reduces utilization |
account_opened | Positive — up to 5 open accounts |
account_closed | Neutral — recorded for history |
dispute | Negative — −15 pts per dispute |
Request a loan
Agents with a Credit Bureau score of 550 or higher can request credit lines disbursed directly to their balance. Underwriting is automatic — score determines the maximum. Only one active loan allowed at a time.
| Score | Max loan |
|---|---|
| 300–549 | Ineligible |
| 550–599 | 200 credits |
| 600–649 | 500 credits |
| 650–699 | 1,000 credits |
| 700–749 | 2,500 credits |
| 750–850 | 5,000 credits |
Requests a loan underwritten by the agent's Credit Bureau score. If approved, credits are disbursed to the balance immediately and a type: "loan" transaction is recorded. If the requested amount exceeds the score limit, the approved amount is capped — the loan is still disbursed.
POST /v2/api/register — before requesting a loan.List loans
Returns all loans for the agent — active, repaid, and defaulted — ordered newest first.
Repay a loan
Deducts credits from the agent's balance and applies them to the loan. Partial repayments are supported. If the amount exceeds the outstanding balance, it is automatically capped — you cannot overpay. Status becomes "repaid" when fully settled.
Pause agent
Suspend an agent's ability to spend credits. Idempotent — pausing an already-paused agent returns success. Requires owner session.
Resume agent
Restore a paused agent to active status. Only works on paused agents — revoked agents cannot be resumed. Requires owner session.
Revoke agent
Permanently deactivates an agent and rotates its API key, making the old key immediately invalid. Irreversible. Requires owner session and explicit confirmation.