Gateway API Reference
The TruePortAI Gateway is a transparent reverse proxy. Your existing AI SDK code requires only a base URL change — no other code modifications needed.
Base URL: https://gateway.trueportai.com
Authentication: All gateway routes require an x-api-key header with a valid TruePortAI API key (sk-...).
Overview
Provider Routes
OpenAI Compatible
Method |
Path |
Description |
|---|---|---|
|
|
Proxy to |
Integration example — Python:
from openai import OpenAI
client = OpenAI(
api_key="sk-your-trueportai-key", # Your TruePortAI key
base_url="https://gateway.trueportai.com/trueportai-services/openai/v1"
)
response = client.chat.completions.create(
model="gpt-4o",
messages=[{"role": "user", "content": "Hello!"}]
)
Integration example — Node.js:
import OpenAI from 'openai';
const client = new OpenAI({
apiKey: 'sk-your-trueportai-key',
baseURL: 'https://gateway.trueportai.com/trueportai-services/openai/v1',
});
const response = await client.chat.completions.create({
model: 'gpt-4o',
messages: [{ role: 'user', content: 'Hello!' }],
});
Anthropic Compatible
Method |
Path |
Description |
|---|---|---|
|
|
Proxy to |
Integration example — Python:
import anthropic
client = anthropic.Anthropic(
api_key="sk-your-trueportai-key",
base_url="https://gateway.trueportai.com/trueportai-services/anthropic/v1"
)
message = client.messages.create(
model="claude-3-5-sonnet-20241022",
max_tokens=1024,
messages=[{"role": "user", "content": "Hello!"}]
)
Google Gemini Compatible
Method |
Path |
Description |
|---|---|---|
|
|
Proxy to |
Azure OpenAI Compatible
Method |
Path |
Description |
|---|---|---|
|
|
Proxy to |
Integration example — Python:
from openai import AzureOpenAI
client = AzureOpenAI(
api_key="sk-your-trueportai-key",
azure_endpoint="https://gateway.trueportai.com/trueportai-services/azure/my-resource/gpt-4o-deploy",
api_version="2024-02-01"
)
Management API
Base path: /trueportai-services/api/v1
Authentication: Authorization: Bearer {scoped_platform_jwt}
API Key Management
POST /keys
Create a new TruePortAI API key.
Request Body:
{
"owner": "production-app",
"rate_limit_rpm": 120
}
Field |
Type |
Required |
Default |
Description |
|---|---|---|---|---|
|
string |
No |
— |
Human-readable label |
|
integer |
No |
|
Requests per minute limit |
Response 201 Created:
{
"id": "64b1f2e3a4c5d6e7f8901234",
"key": "sk-xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
"owner": "production-app",
"is_active": true,
"rate_limit_rpm": 120,
"created_at": "2024-01-15T10:30:00Z"
}
Important: The full
keyvalue is returned only once at creation. Store it securely.
GET /keys
List all API keys for the authenticated tenant.
Query Parameters:
Param |
Type |
Description |
|---|---|---|
|
integer |
Page size (default: 20, max: 100) |
|
integer |
Pagination offset (default: 0) |
Response 200 OK:
[
{
"id": "64b1f2e3a4c5d6e7f8901234",
"key": "sk-xxxx...yyyy",
"owner": "production-app",
"is_active": true,
"rate_limit_rpm": 120,
"created_at": "2024-01-15T10:30:00Z"
}
]
Analytics API
GET /analytics/logs
Retrieve usage logs for the authenticated tenant.
Query Parameters:
Param |
Type |
Description |
|---|---|---|
|
integer |
Page size (default: 50, max: 500) |
|
integer |
Pagination offset |
|
string |
Filter by specific API key |
|
string |
Filter by provider: |
|
datetime |
ISO 8601 start range |
|
datetime |
ISO 8601 end range |
Response 200 OK:
{
"items": [
{
"id": "64b1f2e3a4c5d6e7f8901234",
"timestamp": "2024-01-15T10:30:00Z",
"api_key": "sk-xxxx...yyyy",
"path": "/chat/completions",
"method": "POST",
"status_code": 200,
"latency_ms": 845.2,
"request_size_bytes": 1024,
"response_size_bytes": 4096,
"provider": "openai",
"model": "gpt-4o",
"prompt_tokens": 150,
"completion_tokens": 320,
"cost_usd": 0.00470
}
],
"total": 1284,
"offset": 0,
"limit": 50
}
GET /analytics/stats
Aggregated statistics for the dashboard.
Query Parameters:
Param |
Type |
Description |
|---|---|---|
|
string |
|
Response 200 OK:
{
"period": "7d",
"total_requests": 15420,
"total_cost_usd": 184.32,
"total_tokens": {
"prompt": 2450000,
"completion": 980000,
"total": 3430000
},
"avg_latency_ms": 782.4,
"error_rate_pct": 0.8,
"by_provider": {
"openai": 11200,
"anthropic": 3100,
"google": 1120
},
"by_model": {
"gpt-4o": 8400,
"gpt-4o-mini": 2800,
"claude-3-5-sonnet-20241022": 3100,
"gemini-1.5-pro": 1120
},
"violations": {
"total": 23,
"by_type": {
"pii": 14,
"injection": 6,
"bias": 2,
"exfiltration": 1
},
"critical": 5,
"high": 11
}
}
Violations API
GET /analytics/violations
Retrieve detected violations with filtering.
Query Parameters:
Param |
Type |
Description |
|---|---|---|
|
string |
|
|
string |
|
|
datetime |
ISO 8601 range start |
|
datetime |
ISO 8601 range end |
|
integer |
Default: 20 |
|
integer |
Default: 0 |
Response 200 OK:
{
"items": [
{
"id": "VIO-001",
"usage_log_id": "64b1f2e3a4c5d6e7f8901234",
"type": "pii",
"severity": "critical",
"direction": "request",
"description": "SSN detected in user prompt",
"auto_blocked": false,
"detected_at": "2024-01-15T10:30:00Z",
"model_version": "pii-ner-roberta-v2.1"
}
],
"total": 23
}
GET /analytics/violations/{violation_id}
Get full details of a specific violation including the redacted payload.
Response 200 OK:
{
"id": "VIO-001",
"usage_log_id": "64b1f2e3a4c5d6e7f8901234",
"type": "pii",
"severity": "critical",
"direction": "request",
"description": "SSN detected in user prompt",
"redacted_payload": {
"original_prompt_preview": "My SSN is [REDACTED] and I need...",
"entities_found": [
{ "type": "SSN", "confidence": 0.97 }
]
},
"auto_blocked": false,
"detected_at": "2024-01-15T10:30:00Z",
"model_version": "pii-ner-roberta-v2.1"
}
Policy Rules API
GET /policies
List all governance policy rules for the tenant.
Response 200 OK:
[
{
"id": "pol-001",
"name": "Block credit card numbers",
"action": "block",
"trigger_type": "regex",
"pattern": "\\b(?:4[0-9]{12}(?:[0-9]{3})?|5[1-5][0-9]{14})\\b",
"is_active": true,
"priority": 1
}
]
POST /policies
Create a new policy rule.
Request Body:
{
"name": "Redact phone numbers",
"action": "redact",
"trigger_type": "regex",
"pattern": "\\b\\d{3}[-.]?\\d{3}[-.]?\\d{4}\\b",
"is_active": true,
"priority": 2
}
|
Behavior |
|---|---|
|
Request stopped; 403 returned to client |
|
Matching tokens replaced with |
|
Violation logged; notification sent |
|
Silent audit only |
Health Check
GET /health
Response 200 OK:
{
"status": "healthy",
"version": "v1.0.0",
"services": {
"mongodb": "connected",
"redis": "connected"
}
}
Error Reference
Status |
Code |
Description |
|---|---|---|
|
|
Missing or invalid |
|
|
Key exists but |
|
|
Requests per minute exceeded |
|
|
Downstream provider temporarily unavailable |
|
|
Provider returned an error |
|
|
Malformed request body |
Error response shape:
{
"detail": "Human-readable error message",
"code": "MACHINE_READABLE_CODE",
"retry_after": 47
}