SDK Documentation
Track your AI agent's payments and get a trusted, verifiable credit score — in minutes.
Overview
The gopi. SDK wraps the REST API so you can embed trust scoring directly into your agent runtime. Both SDKs use only standard library modules — no extra dependencies required.
- Python SDK — stdlib only (
urllib.request), LangChain callback included - Node.js SDK — stdlib only (
https/http) - REST API — full control, any language
Installation
pip install gopi-sdk
npm install gopi-sdk
Or copy the single file directly from GitHub — no build step needed:
# Single-file install (no pip required)
curl -o gopi_client.py https://raw.githubusercontent.com/getgopi/sdk/main/gopi_sdk/client.py
Quickstart
Get your API key from the dashboard after registering, then track your first payment:
from gopi_sdk import GopiClient
client = GopiClient(
api_key="gopi_sk_...",
agent_id="your-agent-id",
)
# Track a payment
result = client.track_payment(amount=49.99, status="paid")
print(result) # {"event_id": "...", "status": "paid", ...}
# Request a certificate (requires ≥3 autonomous payments)
cert = client.certify()
print(f"Score: {cert['score']}, Grade: {cert['grade']}, Confidence: {cert['confidence']}")
Python SDK · GopiClient
Constructor
GopiClient(api_key: str, agent_id: str, base_url: str = "https://api.getgopi.io")
| Parameter | Type | Description | |
|---|---|---|---|
| api_key | str | required | Your gopi. API key — get it from dashboard → profile. |
| agent_id | str | required | The agent's external ID shown in the dashboard. |
| base_url | str | optional | Override for self-hosted or staging. Default: https://api.getgopi.io |
Python SDK · track_payment()
Track a payment event for the agent. This is the core method — the more payments you track, the higher the confidence level of your certificate.
client.track_payment(
amount=49.99,
currency="EUR", # default
status="paid", # "paid"|"on_time"|"late"|"missed"|"disputed"
payment_source="agent_wallet", # default — agent paid autonomously
is_autonomous=True, # True = counted toward trust score
date="2024-03-15T12:00:00Z", # ISO 8601, default: now
)
| Parameter | Type | Description | |
|---|---|---|---|
| amount | float | required | Payment amount. Must be > 0. |
| currency | str | optional | ISO 4217 code. Default: "EUR". |
| status | str | optional | One of: paid, on_time, late, missed, disputed. Default: "paid". |
| payment_source | str | optional | agent_wallet, human_card, human_bank, unknown. Default: "agent_wallet". |
| is_autonomous | bool | optional | Set to True if the agent initiated this payment. Only autonomous payments count toward the trust score. Default: True. |
| date | str | optional | ISO 8601 datetime string. Default: current UTC time. |
Python SDK · get_score()
Returns the agent's full public trust profile including current certificate, payment stats, and badge URL.
profile = client.get_score() # { # "gopi_id": "gopi_lch_a1b2c3d4", # "name": "My Finance Bot", # "certificate": { # "score": 87, # "grade": "B", # "confidence": "high", # "valid_until": "2024-06-15T00:00:00Z" # }, # "payment_stats": {"total": 42, "autonomous": 38, "on_time": 36}, # "badge_url": "https://api.getgopi.io/v1/public/gopi_lch_a1b2c3d4/badge.svg" # }
Python SDK · certify()
Request a trust certificate. Calculates the trust score and issues a certificate valid for 90 days. Requires at least 3 autonomous payment events.
Note: Certificates require the basic or professional plan. Free accounts can track payments but not issue certificates.
cert = client.certify() print(cert["score"]) # 0–100 print(cert["grade"]) # A+ / A / B / C / D / F print(cert["confidence"]) # "low" (<5 payments), "medium" (5–20), "high" (>20) print(cert["valid_until"]) # ISO 8601, 90 days from now
Python SDK · LangChain Integration
Use GopiCallbackHandler to automatically track LLM API costs as payment events — zero manual instrumentation.
from langchain_openai import ChatOpenAI
from gopi_sdk.langchain import GopiCallbackHandler
handler = GopiCallbackHandler(
api_key="gopi_sk_...",
agent_id="your-agent-id",
cost_per_1k_tokens=0.002, # e.g. GPT-4o-mini
)
llm = ChatOpenAI(
model="gpt-4o-mini",
callbacks=[handler],
)
# Every LLM call now automatically tracks a payment event
response = llm.invoke("Summarize the quarterly report.")
Each LLM invocation is tracked as an autonomous payment using the actual token count and your configured cost per 1k tokens. Errors are tracked as disputed payments.
Node.js SDK · GopiClient
Constructor
new GopiClient(apiKey: string, agentId: string, baseUrl?: string)
| Parameter | Type | Description | |
|---|---|---|---|
| apiKey | string | required | Your gopi. API key. |
| agentId | string | required | Agent external ID from dashboard. |
| baseUrl | string | optional | Override base URL. Default: https://api.getgopi.io |
Node.js SDK · trackPayment()
await client.trackPayment({ amount: 49.99, currency: 'EUR', status: 'paid', // 'paid'|'on_time'|'late'|'missed'|'disputed' paymentSource: 'agent_wallet', isAutonomous: true, date: new Date().toISOString(), });
Node.js SDK · getScore()
const profile = await client.getScore(); console.log(profile.certificate?.score); // 87 console.log(profile.badge_url); // embed in README or website
Node.js SDK · certify()
const cert = await client.certify(); console.log(`${cert.grade} — ${cert.score}/100 (${cert.confidence} confidence)`);
Reference · Payment Status Values
| Value | Meaning | Score Impact |
|---|---|---|
| paid | Payment completed successfully | ✅ Positive |
| on_time | Payment made on schedule | ✅ Positive |
| late | Payment made but after deadline | ⚠️ Slight negative |
| missed | Payment not made | ❌ Negative |
| disputed | Payment contested or failed | ❌ Strong negative |
Reference · Error Handling
from gopi_sdk import GopiClient, GopiError
try:
cert = client.certify()
except GopiError as e:
print(e.status_code) # HTTP status code
print(e.message) # API error message
if e.status_code == 402:
print("Upgrade to Basic or Professional to certify.")
elif e.status_code == 429:
print("Rate limit hit — wait before retrying.")
Reference · REST API
All SDK methods map to REST endpoints. Use these directly if you prefer curl or a different language.
| Method | Endpoint | Auth | Description |
|---|---|---|---|
| POST | /v1/payment-events | API Key | Track a payment event |
| GET | /v1/agents | JWT | List your agents |
| POST | /v1/agents | JWT | Create a new agent |
| POST | /v1/agents/bulk | JWT | Create up to 10 agents at once |
| GET | /v1/agents/{id} | JWT | Get agent details |
| POST | /v1/agents/{id}/certify | JWT | Request certificate |
| POST | /v1/agents/{id}/renew | JWT | Renew expired certificate |
| POST | /v1/agents/{id}/upload-history | JWT | Bulk import CSV payment history |
| GET | /v1/public/{gopi_id} | None | Public trust profile |
| GET | /v1/public/{gopi_id}/badge.svg | None | SVG trust badge |
| GET | /v1/auth/me | JWT | Get account info + API key |
| DELETE | /v1/auth/delete-account | JWT | DSGVO: delete all data |
| GET | /v1/auth/export-data | JWT | DSGVO: export all data as JSON |
Authentication
Two auth methods are supported depending on the endpoint:
- JWT Bearer — for dashboard/account endpoints:
Authorization: Bearer <token> - API Key — for programmatic/agent endpoints:
X-API-Key: <key>
curl -X POST https://api.getgopi.io/v1/payment-events \
-H "X-API-Key: gopi_sk_..." \
-H "Content-Type: application/json" \
-d '{
"agent_id": "my-finance-bot-abc12345",
"amount": 49.99,
"currency": "EUR",
"status": "paid",
"payment_source": "agent_wallet",
"is_autonomous": true,
"due_at": "2024-03-15T12:00:00Z"
}'
Rate Limits
| Endpoint group | Limit |
|---|---|
| Auth endpoints (register, login, verify) | 5 requests / 15 minutes |
| All other endpoints | 100 requests / minute |
| Public badge/verify endpoints | 100 requests / minute |