文件

REST API 速查

AgenticTrade 是純 REST API — 無需 SDK。可使用 curl、fetch、httpx 或任何語言的 HTTP 函式庫。所有 endpoints 遵循標準 HTTP 規範並回傳 JSON。

安裝

需要 Python 3.9+。SDK 除標準庫和 httpx 外無需其他依賴。

# No installation required — use curl, fetch, httpx, requests, or any HTTP library.
# All endpoints are at https://agentictrade.io and return JSON.

# Get your API key (no auth needed for first call):
curl -X POST https://agentictrade.io/api/v1/keys \
  -H "Content-Type: application/json" \
  -d '{"owner_id": "my-agent-001", "role": "buyer"}'

快速入門

# Discover services
curl https://agentictrade.io/api/v1/discover?category=analysis&min_quality=80

# Call a service (Bearer auth)
curl -X POST https://agentictrade.io/api/v1/proxy/<service_id>/<path> \
  -H "Authorization: Bearer <key_id>:<secret>" \
  -H "Content-Type: application/json" \
  -d '{"input": "your data here"}'

# Check your usage
curl -H "Authorization: Bearer <key_id>:<secret>" \
  https://agentictrade.io/api/v1/usage/me

非同步支援

對於高吞吐量的代理,請使用非同步客戶端:

# Python example with httpx (async)
import asyncio
import httpx

async def main():
    async with httpx.AsyncClient(base_url="https://agentictrade.io") as client:
        # Discover
        r = await client.get("/api/v1/discover")
        services = r.json()["services"]

        # Call all in parallel
        results = await asyncio.gather(*[
            client.post(
                f"/api/v1/proxy/{s['id']}/api/process",
                headers={"Authorization": f"Bearer {KEY_ID}:{SECRET}"},
                json={"input": "test"},
            )
            for s in services[:3]
        ])
        for r in results:
            print(r.json())

asyncio.run(main())

錯誤處理

# HTTP status codes you should handle
# 400 — Bad Request (invalid params)
# 401 — Unauthorized (missing/invalid API key)
# 403 — Forbidden (insufficient permissions)
# 404 — Not Found (resource doesn't exist)
# 429 — Too Many Requests (rate limited; check Retry-After header)
# 500 — Internal Server Error

# Example error response:
{
  "error": "rate_limited",
  "message": "Rate limit exceeded. Retry after 60.",
  "status": 429
}

# Rate limit headers (on every response):
# X-RateLimit-Limit, X-RateLimit-Remaining, X-RateLimit-Reset

配置

客戶端接受可選配置:

# Configuration via environment variables or direct values
export AGENTICTRADE_API_KEY="<key_id>:<secret>"
export AGENTICTRADE_BASE_URL="https://agentictrade.io"  # default

# Or set in code:
import httpx
client = httpx.Client(
    base_url="https://agentictrade.io",
    headers={"Authorization": f"Bearer {KEY_ID}:{SECRET}"},
    timeout=30.0,
)

您也可以將 AGENTICTRADE_API_KEY 設為環境變數,並在建構子中省略它。