Quick Reference Guide
Table of Contents
- Authentication
- Access Token Management
- Making API Calls
- Payment & Credits
- Spending Limits
- Error Codes
- Rate Limiting
- Common Endpoints
Authentication
Register Account
curl -X POST https://api.polysystems.ai/api/auth/register \
-H "Content-Type: application/json" \
-d '{"email": "user@example.com", "password": "SecurePass123!", "username": "myuser"}'Login
curl -X POST https://api.polysystems.ai/api/auth/login \
-H "Content-Type: application/json" \
-d '{"email": "user@example.com", "password": "SecurePass123!"}'Response: JWT token (valid 24 hours)
Access Token Management
Generate Access Token
curl -X POST https://api.polysystems.ai/api/keys \
-H "Authorization: Bearer YOUR_JWT_TOKEN" \
-H "Content-Type: application/json" \
-d '{"name": "My API Key"}'⚠️ Save the key_value immediately - shown only once!
List Access Tokens
curl -X GET https://api.polysystems.ai/api/keys \
-H "Authorization: Bearer YOUR_JWT_TOKEN"Revoke Token
curl -X POST https://api.polysystems.ai/api/keys/{key_id}/revoke \
-H "Authorization: Bearer YOUR_JWT_TOKEN"Delete Token
curl -X DELETE https://api.polysystems.ai/api/keys/{key_id} \
-H "Authorization: Bearer YOUR_JWT_TOKEN"Making API Calls
Two Ways to Authenticate
Method 1: X-API-Key Header (Recommended)
curl -X POST https://api.polysystems.ai/api/hub/agents/chat \
-H "X-API-Key: YOUR_ACCESS_TOKEN" \
-H "Content-Type: application/json" \
-d '{"messages": [{"role": "user", "content": "Hello"}]}'Method 2: Authorization Bearer
curl -X POST https://api.polysystems.ai/api/hub/agents/chat \
-H "Authorization: Bearer YOUR_ACCESS_TOKEN" \
-H "Content-Type: application/json" \
-d '{"messages": [{"role": "user", "content": "Hello"}]}'Payment & Credits
Check Balance
curl -X GET https://api.polysystems.ai/api/payments/credits/balance \
-H "Authorization: Bearer YOUR_JWT_TOKEN"Create Payment (x402)
curl -X POST https://api.polysystems.ai/api/payments/payments \
-H "Authorization: Bearer YOUR_JWT_TOKEN" \
-H "Content-Type: application/json" \
-d '{"amount_usd": 50.00, "currency": "ETH"}'Supported Currencies: BTC, ETH, SOL
Check Payment Status
curl -X GET https://api.polysystems.ai/api/payments/payments/{payment_id} \
-H "Authorization: Bearer YOUR_JWT_TOKEN"List Transactions
curl -X GET https://api.polysystems.ai/api/payments/transactions?limit=10 \
-H "Authorization: Bearer YOUR_JWT_TOKEN"Spending Limits
Set Spending Limits
curl -X PUT https://api.polysystems.ai/api/keys/{key_id}/limits \
-H "Authorization: Bearer YOUR_JWT_TOKEN" \
-H "Content-Type: application/json" \
-d '{
"daily_limit": 10.00,
"monthly_limit": 250.00,
"per_request_limit": 1.00
}'Get Limits
curl -X GET https://api.polysystems.ai/api/keys/{key_id}/limits \
-H "Authorization: Bearer YOUR_JWT_TOKEN"Reset Spending Counters
curl -X POST https://api.polysystems.ai/api/keys/{key_id}/limits/reset \
-H "Authorization: Bearer YOUR_JWT_TOKEN"Remove All Limits
curl -X DELETE https://api.polysystems.ai/api/keys/{key_id}/limits \
-H "Authorization: Bearer YOUR_JWT_TOKEN"Error Codes
| Code | Status | Common Cause | Solution |
|---|---|---|---|
| 400 | Bad Request | Invalid request format | Check request body/params |
| 401 | Unauthorized | Missing/invalid API key | Check authentication |
| 402 | Payment Required | Insufficient credits | Add credits or check limits |
| 403 | Forbidden | No permission | Check account permissions |
| 404 | Not Found | Resource doesn’t exist | Verify resource ID |
| 429 | Too Many Requests | Rate limit exceeded | Slow down, check Retry-After header |
| 500 | Internal Server Error | Server issue | Retry with backoff |
| 503 | Service Unavailable | Temporary outage | Retry later |
Rate Limiting
Rate Limit Headers
X-RateLimit-Limit: 1000 # Total allowed in window
X-RateLimit-Remaining: 999 # Requests remaining
X-RateLimit-Reset: 1705327200 # Unix timestamp when resets
X-RateLimit-Window: 3600 # Window in secondsDefault Limits
| Tier | Requests/Second | Requests/Minute | Requests/Hour |
|---|---|---|---|
| Free | 1 | 10 | 100 |
| Basic | 5 | 100 | 1,000 |
| Pro | 20 | 1,000 | 10,000 |
| Enterprise | Custom | Custom | Custom |
Handle Rate Limit Errors
import time
import requests
response = requests.post(url, headers=headers, json=data)
if response.status_code == 429:
retry_after = int(response.headers.get('Retry-After', 60))
time.sleep(retry_after)
# Retry requestCommon Endpoints
Health Check (Public)
curl https://api.polysystems.ai/api/hub/healthChat Completion
curl -X POST https://api.polysystems.ai/api/hub/agents/chat \
-H "X-API-Key: YOUR_TOKEN" \
-d '{
"messages": [
{"role": "system", "content": "You are helpful."},
{"role": "user", "content": "Hello!"}
],
"temperature": 0.7,
"max_tokens": 500
}'Store Memory
curl -X POST https://api.polysystems.ai/api/hub/memory \
-H "X-API-Key: YOUR_TOKEN" \
-d '{
"key": "user_pref",
"value": "dark_mode",
"metadata": {"user_id": "123"}
}'Search Memory
curl -X POST https://api.polysystems.ai/api/hub/memory/search \
-H "X-API-Key: YOUR_TOKEN" \
-d '{"query": "user preferences", "limit": 10}'Submit Task
curl -X POST https://api.polysystems.ai/api/hub/tasks \
-H "X-API-Key: YOUR_TOKEN" \
-d '{
"task_type": "data_processing",
"parameters": {"input": "data.csv"},
"priority": "high"
}'Get Task Status
curl -X GET https://api.polysystems.ai/api/hub/tasks/{task_id} \
-H "X-API-Key: YOUR_TOKEN"RAG - Index Document
curl -X POST https://api.polysystems.ai/api/hub/rag/index \
-H "X-API-Key: YOUR_TOKEN" \
-d '{
"content": "Document content here...",
"metadata": {"title": "My Document"}
}'RAG - Generate with Context
curl -X POST https://api.polysystems.ai/api/hub/rag/generate \
-H "X-API-Key: YOUR_TOKEN" \
-d '{"query": "What is...?", "top_k": 5}'Pricing Quick Reference
Base Prices (USD)
| Endpoint Type | Base Price | Token Price | Example Cost |
|---|---|---|---|
| Memory Operations | $0.0001 | N/A | $0.0001 |
| Chat Completion | $0.0020 | $0.00001/token | 0.05 |
| RAG Generation | $0.0030 | $0.00001/token | 0.10 |
| OMM Processing | $0.0030 | $0.00002/token | 0.10 |
| Legal Analysis | $0.0050 | $0.00003/token | 0.15 |
Cost Headers
X-Request-Cost: 0.0035 # Cost of this request
X-Tokens-Used: 150 # Tokens processed
X-Balance-Remaining: 47.2915 # Remaining balanceEnvironment Variables
# Required
export PS_API_KEY="ps_live_your_access_token"
# Optional
export PS_API_URL="https://api.polysystems.ai"
export PS_JWT_TOKEN="your_jwt_token"Code Snippets
Python
import os
import requests
API_KEY = os.getenv('PS_API_KEY')
BASE_URL = "https://api.polysystems.ai"
def chat(message):
response = requests.post(
f"{BASE_URL}/api/hub/agents/chat",
headers={'X-API-Key': API_KEY, 'Content-Type': 'application/json'},
json={'messages': [{'role': 'user', 'content': message}]}
)
return response.json()
result = chat("Hello!")
print(result)Node.js
const axios = require('axios');
const API_KEY = process.env.PS_API_KEY;
const BASE_URL = 'https://api.polysystems.ai';
async function chat(message) {
const response = await axios.post(
`${BASE_URL}/api/hub/agents/chat`,
{ messages: [{ role: 'user', content: message }] },
{ headers: { 'X-API-Key': API_KEY } }
);
return response.data;
}
chat('Hello!').then(console.log);cURL with Environment Variable
curl -X POST https://api.polysystems.ai/api/hub/agents/chat \
-H "X-API-Key: $PS_API_KEY" \
-H "Content-Type: application/json" \
-d '{"messages": [{"role": "user", "content": "Hello"}]}'Best Practices Checklist
Security
- ✅ Never hardcode API keys
- ✅ Use environment variables or secrets manager
- ✅ Rotate keys every 90 days
- ✅ Use different keys for dev/staging/prod
- ✅ Set spending limits on all tokens
Performance
- ✅ Implement response caching
- ✅ Use connection pooling
- ✅ Batch operations when possible
- ✅ Handle rate limits gracefully
- ✅ Implement request deduplication
Cost Optimization
- ✅ Optimize prompts to reduce tokens
- ✅ Set max_tokens limits
- ✅ Cache frequent queries
- ✅ Use batch endpoints
- ✅ Monitor spending daily
Error Handling
- ✅ Wrap all API calls in try-catch
- ✅ Implement exponential backoff
- ✅ Log errors with context
- ✅ Handle all HTTP status codes
- ✅ Provide user-friendly error messages
Monitoring
- ✅ Log all API requests
- ✅ Track costs and usage
- ✅ Set up balance alerts
- ✅ Monitor rate limit usage
- ✅ Implement health checks
Common Issues
”Invalid API key”
- Check key is correct (no typos)
- Verify key is still active
- Confirm key hasn’t expired
- Try regenerating key
”Insufficient credits”
- Check balance:
/api/payments/credits/balance - Add credits via x402 payment
- Verify payment was confirmed
”Spending limit exceeded”
- Check limits:
/api/keys/{key_id}/limits - Wait for daily/monthly reset
- Increase limits or use different token
”Rate limit exceeded”
- Check rate limit headers
- Implement exponential backoff
- Reduce request frequency
- Consider upgrading tier
Support
- Documentation: Full Developer Docs
- Email: support@polysystems.ai
- Enterprise: enterprise@polysystems.ai
Useful Links
- Getting Started Guide
- Authentication Deep Dive
- Access Token Management
- API Routing Reference
- Payment System
- Spending Limits
- Pricing Information
- Webhooks Guide
- Rate Limiting
- Error Handling
- Code Examples
- Best Practices
Last Updated: 2024-01-15