AI Service API
AI-powered transaction analysis, risk assessment, and wallet suggestions with TEE-secured inference. Provides chat completions, embeddings, and specialized blockchain analytics.
Service Architecture
| Protocol | Port | Description |
|---|
| gRPC | 9099 | Internal API (Tonic/Prost) |
| HTTP | 8089 | REST API and health checks |
Authentication
All endpoints require multi-tenant authentication:
X-Tenant-Id: your-tenant-id
X-API-Key: your-api-key
REST Endpoints
Health & Metrics
| Method | Path | Description |
|---|
GET | /health | Health check |
GET | /healthz | Liveness probe |
GET | /readyz | Readiness probe (checks model availability) |
GET | /metrics | Prometheus metrics with GPU stats |
Transaction Analysis
| Method | Path | Description |
|---|
POST | /api/ai/analyze/transaction | Analyze transaction for risk |
POST | /api/ai/analyze/bridge | Analyze cross-chain bridge operations |
POST | /api/ai/check/address | Check if address is potentially malicious |
Chat & Suggestions
| Method | Path | Description |
|---|
POST | /api/ai/chat | Chat with AI about wallet operations |
POST | /api/ai/suggestions | Get AI-powered wallet suggestions |
GET | /api/ai/gas/:chain | Get gas optimization recommendations |
Model Inference
| Method | Path | Description |
|---|
POST | /api/ai/infer | Run text completion inference |
POST | /api/ai/embed | Generate embeddings |
GET | /api/ai/models | List available models |
GET | /api/ai/models/:id | Get specific model information |
Analyze Transaction
POST /api/ai/analyze/transaction
X-Tenant-Id: your-tenant-id
Content-Type: application/json
{
"txHash": "0xa1b2c3d4...",
"chain": "ethereum",
"from": "0x742d35Cc6634C0532925a3b844Bc9e7595f3...",
"to": "0x123456789abcdef...",
"value": "1000000000000000000",
"data": "0x..."
}
Response
{
"data": {
"riskScore": 0.15,
"riskLevel": "low",
"flags": [],
"analysis": "Transaction appears to be a standard ERC-20 transfer...",
"recommendations": []
}
}
Check Address
POST /api/ai/check/address
X-Tenant-Id: your-tenant-id
Content-Type: application/json
{
"address": "0x742d35Cc6634C0532925a3b844Bc9e7595f3...",
"chain": "ethereum"
}
Response
{
"data": {
"address": "0x742d35Cc6634C0532925a3b844Bc9e7595f3...",
"isMalicious": false,
"confidence": 0.95,
"labels": [],
"lastChecked": "2024-01-15T10:30:00Z"
}
}
Chat
POST /api/ai/chat
X-Tenant-Id: your-tenant-id
Content-Type: application/json
{
"messages": [
{
"role": "user",
"content": "What's the best way to bridge USDC from Ethereum to Base?"
}
],
"context": {
"walletAddress": "0x...",
"chain": "ethereum"
}
}
Response
{
"data": {
"response": "To bridge USDC from Ethereum to Base, I recommend...",
"suggestions": [
{
"action": "bridge",
"params": { "fromChain": "ethereum", "toChain": "base", "asset": "USDC" }
}
]
}
}
Run Inference
POST /api/ai/infer
X-Tenant-Id: your-tenant-id
Content-Type: application/json
{
"model": "gpt-4",
"messages": [
{
"role": "system",
"content": "You are a blockchain transaction analyst."
},
{
"role": "user",
"content": "Analyze this transaction for potential risks."
}
],
"temperature": 0.7,
"maxTokens": 1000
}
Response
{
"data": {
"id": "inf_abc123",
"model": "gpt-4",
"content": "Based on my analysis...",
"usage": {
"promptTokens": 150,
"completionTokens": 250,
"totalTokens": 400
},
"finishReason": "stop"
}
}
Generate Embeddings
POST /api/ai/embed
X-Tenant-Id: your-tenant-id
Content-Type: application/json
{
"model": "text-embedding-3-small",
"input": [
"Transaction from wallet 0x742d to 0x123f",
"Cross-chain bridge transfer USDC to Polygon"
],
"dimensions": 512
}
Response
{
"data": {
"embeddings": [
{
"index": 0,
"embedding": [0.0023, -0.0451, 0.0321, ...]
},
{
"index": 1,
"embedding": [0.0145, -0.0234, 0.0567, ...]
}
],
"model": "text-embedding-3-small",
"usage": {
"promptTokens": 25,
"totalTokens": 25
}
}
}
Get Gas Recommendations
GET /api/ai/gas/ethereum
X-Tenant-Id: your-tenant-id
Response
{
"data": {
"chain": "ethereum",
"recommendations": {
"slow": { "maxFeePerGas": "20000000000", "estimatedTime": "5m" },
"standard": { "maxFeePerGas": "30000000000", "estimatedTime": "2m" },
"fast": { "maxFeePerGas": "50000000000", "estimatedTime": "30s" }
},
"insight": "Gas prices are elevated due to high network activity"
}
}
List Models
GET /api/ai/models
X-Tenant-Id: your-tenant-id
Response
{
"data": [
{
"id": "gpt-4",
"name": "GPT-4",
"type": "chat",
"provider": "openai",
"contextWindow": 8192,
"available": true
},
{
"id": "text-embedding-3-small",
"name": "Text Embedding 3 Small",
"type": "embedding",
"provider": "openai",
"dimensions": 1536,
"available": true
}
]
}
Risk Levels
| Level | Score Range | Description |
|---|
low | 0.0 - 0.3 | Transaction appears safe |
medium | 0.3 - 0.6 | Review recommended |
high | 0.6 - 0.8 | Proceed with caution |
critical | 0.8 - 1.0 | High risk, not recommended |
Error Codes
| Code | Description |
|---|
MODEL_NOT_FOUND | Requested model does not exist |
CONTEXT_LENGTH_EXCEEDED | Input exceeds model context window |
RATE_LIMIT_EXCEEDED | Too many requests |
INVALID_CHAIN | Chain not supported |