Proxy API Reference
Technical documentation for the AiSpendTrack proxy API.
Base URL
https://proxy.aispendtrack.comAuthentication
All requests must include your AiSpendTrack API key in headers:
x-aispendtrack-key: ask_your_key_hereEndpoints
OpenAI Proxy
Base URL:
https://proxy.aispendtrack.com/v1Supported endpoints:
/v1/chat/completions- Chat completions/v1/completions- Text completions/v1/embeddings- Embeddings/v1/images/generations- Image generation
Example request:
curl https://proxy.aispendtrack.com/v1/chat/completions \
-H "Content-Type: application/json" \
-H "Authorization: Bearer YOUR_OPENAI_KEY" \
-H "x-aispendtrack-key: YOUR_AISPENDTRACK_KEY" \
-d '{
"model": "gpt-4",
"messages": [{"role": "user", "content": "Hello!"}]
}'Anthropic Proxy
Base URL:
https://proxy.aispendtrack.com/anthropic/v1Supported endpoints:
/anthropic/v1/messages- Messages API/anthropic/v1/complete- Completions (legacy)
Example request:
curl https://proxy.aispendtrack.com/anthropic/v1/messages \
-H "Content-Type: application/json" \
-H "x-api-key: YOUR_ANTHROPIC_KEY" \
-H "anthropic-version: 2023-06-01" \
-H "x-aispendtrack-key: YOUR_AISPENDTRACK_KEY" \
-d '{
"model": "claude-3-opus-20240229",
"max_tokens": 1024,
"messages": [{"role": "user", "content": "Hello!"}]
}'Optional Headers
Customer Tracking
Track costs per customer:
x-customer-id: customer_123The customer ID can be any string (user ID, email, account number).
Feature Tracking
Track costs per feature:
x-feature: chat-supportThe feature name can be any string identifying the feature.
Combined Example
curl https://proxy.aispendtrack.com/v1/chat/completions \
-H "Authorization: Bearer YOUR_OPENAI_KEY" \
-H "x-aispendtrack-key: YOUR_AISPENDTRACK_KEY" \
-H "x-customer-id: user_789" \
-H "x-feature: content-generation" \
-d '{
"model": "gpt-4",
"messages": [{"role": "user", "content": "Write a blog post"}]
}'This call will be tracked with:
- Model: gpt-4
- Customer: user_789
- Feature: content-generation
Response Headers
AiSpendTrack adds these headers to responses:
x-aispendtrack-cost: 0.0045
x-aispendtrack-tokens: 225
x-aispendtrack-latency: 1234Headers:
x-aispendtrack-cost- Cost in USDx-aispendtrack-tokens- Total tokens usedx-aispendtrack-latency- Proxy latency in milliseconds
These headers are informational only. Full details appear in your dashboard.
Error Responses
401 Unauthorized
Cause: Missing or invalid AiSpendTrack API key
Response:
{
"error": {
"message": "Invalid or missing x-aispendtrack-key header",
"type": "authentication_error",
"code": "invalid_api_key"
}
}Solution: Verify your API key is correct and in headers.
429 Rate Limit Exceeded
Cause: You’ve exceeded your rate limit or monthly limit
Response:
{
"error": {
"message": "Rate limit exceeded",
"type": "rate_limit_error",
"code": "rate_limit_exceeded",
"retry_after": 3600,
"current_usage": 10000,
"limit": 10000,
"upgrade_url": "https://app.aispendtrack.com/upgrade"
}
}Headers:
retry-after: 3600
x-ratelimit-limit: 10000
x-ratelimit-remaining: 0
x-ratelimit-reset: 1708272000Solution:
- Wait for
retry-afterseconds - Or upgrade your plan
502 Bad Gateway
Cause: OpenAI/Anthropic is down or unreachable
Response:
{
"error": {
"message": "Upstream provider temporarily unavailable",
"type": "service_error",
"code": "upstream_error"
}
}Solution: Retry with exponential backoff.
Rate Limits
| Tier | Rate Limit | Monthly Limit |
|---|---|---|
| Free | 1,000 req/hour | 10,000 calls |
| Pro | 10,000 req/hour | Unlimited |
| Enterprise | Custom | Unlimited |
Rate limit headers:
x-ratelimit-limit: 1000
x-ratelimit-remaining: 847
x-ratelimit-reset: 1708272000Streaming
Streaming is fully supported and works identically to direct API calls.
OpenAI streaming:
const stream = await openai.chat.completions.create({
model: "gpt-4",
messages: [{ role: "user", content: "Write a story" }],
stream: true
});
for await (const chunk of stream) {
process.stdout.write(chunk.choices[0]?.delta?.content || '');
}Anthropic streaming:
with client.messages.stream(
model="claude-3-opus-20240229",
max_tokens=1024,
messages=[{"role": "user", "content": "Write a story"}]
) as stream:
for text in stream.text_stream:
print(text, end='', flush=True)Streaming responses are tracked the same as non-streaming. Costs appear after stream completes.
Latency
Average latency overhead: <300ms
Latency breakdown:
- Header processing: ~5ms
- Database logging (async): ~50ms (doesn’t block response)
- Network overhead: ~50-100ms
- Total added latency: ~60ms on average
The proxy forwards your request immediately and logs metadata asynchronously.
Data Logged
For each API call, we log:
{
"id": "call_abc123",
"timestamp": "2024-02-18T14:30:00Z",
"customer_id": "cust_123",
"provider": "openai",
"model": "gpt-4",
"endpoint": "/v1/chat/completions",
"prompt_tokens": 150,
"completion_tokens": 75,
"total_tokens": 225,
"cost_usd": 0.0045,
"latency_ms": 1234,
"status_code": 200,
"error_type": null,
"customer_id": "user_789",
"feature": "content-generation"
}We never log:
- ❌ Your prompts
- ❌ AI responses
- ❌ API keys (yours or OpenAI/Anthropic)
- ❌ User data in prompts
Health Check
Endpoint:
GET /healthResponse:
{
"status": "ok",
"uptime": 1234567,
"version": "1.0.0"
}Use for monitoring or load balancer health checks.
Regional Endpoints
Currently, we have one global endpoint:
https://proxy.aispendtrack.comComing soon:
- 🔜 EU endpoint (GDPR compliance)
- 🔜 Asia-Pacific endpoint (lower latency)
Enterprise customers can request dedicated endpoints.
SDK Support
Works with official SDKs:
Supported:
- ✅
openai(Node.js, Python) - ✅
@anthropic-ai/sdk(Node.js) - ✅
anthropic(Python) - ✅ Any HTTP client (Go, Ruby, Java, etc.)
Configuration:
- Change
baseURL/base_url - Add
x-aispendtrack-keyheader
No custom SDK required!