SentinelMeshAI Documentation
Complete reference for the SentinelMeshAI AI Gateway — multi-model routing, self-learning optimisation, and enterprise-grade orchestration.
Core Concepts
Before integrating, these five concepts explain what SentinelMeshAI does differently from a direct LLM API call.
Request Lifecycle
Auth · Rate limit → Semantic Cache
Hit? Return now → Bandit Router
Select strategy → LLM Adapters
1–5 models → RL Update
Learn reward → Response
Strategies
A strategy defines which models to call and how to combine their answers. The router automatically selects the best strategy per request based on learned performance. You can also request a strategy explicitly.
| Strategy | Models called | Best for | Approx. cost |
|---|---|---|---|
fast_cheap | DeepSeek Chat | High-volume, cost-critical | $0.00014/1K tok |
standard | Claude 3.5 Sonnet | General-purpose, best value | $0.003/1K tok |
fast_reasoning | o3-mini | Math, logic, structured output | $0.0011/1K tok |
code_specialist | Codestral | Code generation & review | $0.0002/1K tok |
rag_specialist | Command-R-Plus | RAG, retrieval, long docs | $0.0025/1K tok |
parallel_ensemble | GPT-4.1 + Claude + Gemini + DeepSeek + Groq | Critical decisions, consensus | ~$0.006/1K tok |
high_accuracy | GPT-4.1 + Claude 3.7 + Gemini 2.5 Pro + o1 | Maximum accuracy, frontier tasks | ~$0.025/1K tok |
Tenancy & API Keys
Every API key maps to a tenant. Each tenant has its own rate limit, usage budget, billing tier, learning state, and WorldModel. Keys look like sm_live_... (production) or sm_test_... (testing, never billed).
Quickstart 5 min
Sign up at app.sentinelmeshai.com → Dashboard → API Keys → New Key. Your key starts with sm_live_.
bashcurl -X POST https://api.sentinelmeshai.com/run \
-H "Authorization: Bearer sm_live_YOUR_KEY" \
-H "Content-Type: application/json" \
-d '{"prompt": "Explain quantum entanglement in one paragraph."}'
pythonimport os, sentinelmeshai as sm
sm.api_key = os.getenv("SENTINELMESHAI_API_KEY")
result = sm.run("Explain quantum entanglement in one paragraph.")
print(result["output"])
# → "Quantum entanglement is a phenomenon..."
print(f"Model : {result['models_used']}")
print(f"Cost : ${result['cost_usd']:.6f}")
print(f"Latency: {result['latency_ms']}ms")
javascriptimport SentinelMeshAI from 'sentinelmeshai';
const sm = new SentinelMeshAI({ apiKey: process.env.SENTINELMESHAI_API_KEY });
const result = await sm.run("Explain quantum entanglement in one paragraph.");
console.log(result.output);
console.log(`Cost: $${result.cost_usd.toFixed(6)}`);
console.log(`Models: ${result.models_used.join(', ')}`);
gopackage main
import (
"fmt"
sm "github.com/sentinelmeshai/go-sdk"
)
func main() {
client := sm.New(sm.Config{APIKey: os.Getenv("SENTINELMESHAI_API_KEY")})
result, _ := client.Run("Explain quantum entanglement in one paragraph.")
fmt.Println(result.Output)
fmt.Printf("Cost: $%.6f\n", result.CostUSD)
}
{
"output": "Quantum entanglement is a phenomenon where two particles...",
"models_used": ["anthropic:claude-3-5-sonnet-20241022"],
"strategy_used": "standard",
"cost_usd": 0.000843,
"latency_ms": 412,
"confidence": 0.97,
"cached": false,
"trace_id": "tr_8f3a2b91c4d05e67"
}
Authentication
All requests require a Bearer token in the Authorization header.
httpAuthorization: Bearer sm_live_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
| Header | Value | Required |
|---|---|---|
Authorization | Bearer sm_live_... | required |
Content-Type | application/json | required |
X-Request-ID | Your trace ID (e.g. UUID) | optional |
X-Session-ID | Persistent session for memory | optional |
Platform Architecture
The AI engine handles all LLM calls. It exposes 84 HTTP endpoints covering inference, streaming, vision, voice, workflows, benchmarks, and admin operations. It persists all state (tenants, billing, WorldModel, traces) to SQLite volumes — no external DB required.
The customer-facing platform. Handles auth, billing (Stripe), dashboard, admin portal, and plan management. Syncs tenants to the FastAPI engine via private internal networking on first registration and on plan upgrades.
Thin client libraries for Python and Node.js. Wraps the HTTP API with typed methods, error classes, streaming helpers, and async support. No runtime dependencies beyond httpx (Python) or the fetch API (Node).
AI Router — Bandit + Reinforcement Learning
The router uses a contextual LinUCB bandit to select the strategy for each request. After the response is returned, it observes a reward signal (response quality × inverse cost) and updates arm weights. Over time, it learns which strategies work best for your specific workload — automatically.
python# Request a specific strategy explicitly (overrides the router)
result = await router.route(
prompt = "Debug this Python traceback...",
strategy = "code_specialist", # pin to Codestral
context = {"temperature": 0.1, "max_tokens": 2048},
tenant_id = "ten_abc123",
)
POST /run
Request body
| Field | Type | Description |
|---|---|---|
promptrequired | string | The input text to send to the model. Max 32,000 tokens. |
strategyoptional | string | Force a strategy: fast_cheap, standard, parallel_ensemble, high_accuracy, etc. |
temperatureoptional | float | 0.0–1.0. Default: 0.2. Higher = more creative, lower = more deterministic. |
max_tokensoptional | int | Maximum output tokens. Default: 1024. Max: 16384. |
system_promptoptional | string | System-level instructions prepended to every message. |
metadataoptional | object | Arbitrary key-value pairs attached to the trace (useful for analytics). |
Response
| Field | Type | Description |
|---|---|---|
output | string | The model's response text. |
models_used | string[] | List of adapter names that contributed (e.g. ["anthropic:claude-3-5-sonnet-20241022"]). |
strategy_used | string | Which strategy was selected. |
cost_usd | float | Total cost in USD for this request. |
latency_ms | int | End-to-end latency in milliseconds. |
confidence | float | 0.0–1.0 confidence estimate from the router. |
cached | boolean | true if the response was served from semantic cache. |
trace_id | string | Unique request identifier for debugging. |
POST /run-with-memory
Additional fields
| Field | Type | Description |
|---|---|---|
session_idrequired | string | Identifies the conversation. Use a UUID or your own user/chat ID. Sessions persist for 7 days. |
window_sizeoptional | int | Max previous turns to include. Default: 10. Max: 50. |
pythonSESSION = "user_12345_chat_001"
# Turn 1
r1 = sm.run_with_memory("My name is Alex.", session_id=SESSION)
# Turn 2 — model remembers "Alex"
r2 = sm.run_with_memory("What's my name?", session_id=SESSION)
print(r2["output"]) # "Your name is Alex."
POST /run-cached
python# First call — goes to LLM
r1 = sm.run_cached("What is the capital of France?")
print(r1["cached"]) # False, cost_usd: 0.000120
# Semantically similar call — served from cache
r2 = sm.run_cached("Tell me the capital city of France")
print(r2["cached"]) # True, cost_usd: 0.000000
POST /run-stream
pythonimport asyncio, sentinelmeshai as sm
sm.api_key = "sm_live_..."
async def stream_example():
async for chunk in sm.astream("Write a 200-word essay on recursion."):
print(chunk, end="", flush=True)
asyncio.run(stream_example())
javascriptconst sm = new SentinelMeshAI({ apiKey: process.env.SENTINELMESHAI_API_KEY });
const stream = await sm.stream("Write a 200-word essay on recursion.");
for await (const chunk of stream) {
process.stdout.write(chunk);
}
GET /usage
Semantic Caching
SentinelMeshAI embeds every prompt using sentence-transformers/all-MiniLM-L6-v2 and compares cosine similarity against the cache. Hits with similarity > 0.92 are returned instantly at zero cost. The cache is per-tenant and persists for 24 hours.
python# Use /run-cached endpoint, or add "use_cache": true to /run body
result = requests.post(API_URL + "/run-cached", ...)
# Check if cached
if result.json()["cached"]:
print("Free! Served from semantic cache.")
else:
print(f"LLM call — cost: ${result.json()['cost_usd']:.6f}")
Memory & Sessions
Sessions are identified by session_id. SentinelMeshAI stores the conversation window in a vector store (SQLite + in-memory embeddings) and prepends relevant context on each turn. Sessions expire after 7 days of inactivity.
| Concept | Description | Default |
|---|---|---|
| Session ID | Your identifier for a conversation thread | Required by caller |
| Window size | Max previous turns included in context | 10 turns |
| Expiry | Sessions older than N days of inactivity are pruned | 7 days |
| Storage | Per-tenant SQLite on Railway Volume | Auto-provisioned |
Streaming Responses
Use the /run-stream endpoint for any response longer than ~100 tokens. Streaming reduces perceived latency to near-zero and allows progressive rendering in UI components.
astream() (Python) and stream() (Node.js) handle SSE parsing automatically — you just iterate chunks.
Vision & Multimodal
Send images alongside prompts using base64 encoding. The vision pipeline routes to OpenAI GPT-4o (default) or Google Gemini 2.0 Flash depending on task type.
pythonimport base64, requests
with open("chart.png", "rb") as f:
image_b64 = base64.b64encode(f.read()).decode()
result = requests.post(
"https://api.sentinelmeshai.com/vision/analyze",
headers={"Authorization": f"Bearer {API_KEY}"},
json={
"image": image_b64,
"prompt": "Extract all data from this bar chart as JSON.",
"vision_model": "gpt-4o" # or "gemini-2.0-flash"
}
).json()
print(result["output"])
Function Calling
Define tools as Python functions and register them with the ToolRegistry. The model decides when to call tools, SentinelMeshAI executes them and feeds results back — automatically, with loop protection (max 5 rounds).
pythonfrom core.tools.base_tool import BaseTool
from core.tools.tool_registry import ToolRegistry
from core.agents.tool_agent import ToolAgent
from app import router
class WeatherTool(BaseTool):
name = "get_weather"
description = "Get current weather for a city"
async def execute(self, city: str) -> str:
# Call your weather API here
return f"72°F, sunny in {city}"
registry = ToolRegistry()
registry.register(WeatherTool())
agent = ToolAgent("assistant", router=router, tool_registry=registry)
result = await agent.run("What's the weather in Lagos right now?")
print(result.output) # "It is currently 72°F and sunny in Lagos."
Webhooks
SentinelMeshAI can push events to your endpoint when key things happen: model training completes, usage thresholds are crossed, or benchmarks detect regressions.
python# Register a webhook (POST /admin/webhook — requires X-Admin-Key)
requests.post(
"https://api.sentinelmeshai.com/admin/webhook",
headers={"X-Admin-Key": ADMIN_KEY},
json={
"url": "https://yourapp.com/webhooks/sentinelmeshai",
"events": ["model.trained", "usage.threshold", "benchmark.regression"],
"secret": "your_webhook_secret"
}
)
event, timestamp, tenant_id, and data. Verify the X-Webhook-Signature header (HMAC-SHA256 of the raw body using your secret) before processing.
Error Codes
Authorization: Bearer header.Retry-After header gives seconds to wait.detail array in the response for field-level errors.Retries & Timeouts
pythonimport httpx, time
def call_with_retry(prompt, max_retries=3):
for attempt in range(max_retries):
try:
r = httpx.post(
"https://api.sentinelmeshai.com/run",
headers={"Authorization": f"Bearer {API_KEY}"},
json={"prompt": prompt},
timeout=30.0
)
if r.status_code == 429:
wait = int(r.headers.get("Retry-After", 2 ** attempt))
time.sleep(wait)
continue
r.raise_for_status()
return r.json()
except httpx.TimeoutException:
if attempt == max_retries - 1: raise
time.sleep(2 ** attempt)
raise RuntimeError("Max retries exceeded")
Model Catalog
| Model name | Provider | Strengths | Input $/1K tok |
|---|---|---|---|
openai:gpt-4.1-mini | OpenAI | Fast, cost-efficient default | $0.00015 |
openai:gpt-4o | OpenAI | Multimodal flagship | $0.00250 |
openai:o3-mini | OpenAI | Fast reasoning | $0.00110 |
anthropic:claude-3-5-sonnet-20241022 | Anthropic | Best value all-rounder | $0.00300 |
anthropic:claude-3-7-sonnet-20250219 | Anthropic | Extended thinking | $0.00300 |
google:gemini-2.0-flash | Fast, 1M context | $0.00010 | |
google:gemini-2.5-pro | Frontier, coding | $0.00125 | |
mistral:codestral | Mistral | Code generation | $0.00020 |
deepseek:deepseek-chat | DeepSeek | Cheapest capable model | $0.00014 |
cohere:command-r-plus | Cohere | RAG, retrieval | $0.00250 |
groq:llama-3.3-70b-versatile | Groq | Open model, ultra-low latency | $0.00059 |
📚 SentinelMeshAI Docs · Last updated April 2026 · v1.0.0
Tutorials · SDK Reference · Dashboard