Documentation
Everything you need to integrate LLMShield into your application.
Quick Start
LLMShield exposes an OpenAI-compatible endpoint. Point any existing OpenAI client at your gateway URL and you're done.
curl -X POST https://your-gateway.onrender.com/v1/chat/completions \
-H "Content-Type: application/json" \
-d '{
"messages": [
{ "role": "user", "content": "What is LLMShield?" }
]
}'That's it. Your request is now automatically cached, guarded against PII, routed to the optimal model, and logged with cost data.
SDK Integration
The LLMShield SDK provides a lightweight wrapper around the gateway API, giving you a clean interface to integrate LLMShield into any Node.js application.
npm link to integrate it locally into your projects.Local Setup via npm link
# From the LLMShield project root, link the SDK globally
cd sdk
npm link
# Then, in your application directory
cd /path/to/your-app
npm link llmshield-sdkSimple usage
const { createLLMClient } = require('llmshield-sdk');
const client = createLLMClient({
baseURL: 'https://your-gateway.onrender.com'
});
// Simple: just pass a prompt string
const answer = await client.chat('What is machine learning?');
console.log(answer);Advanced usage (full OpenAI body)
// Use chatRaw() for full control over the request body
const response = await client.chatRaw({
messages: [
{ role: 'system', content: 'You are a helpful coding assistant.' },
{ role: 'user', content: 'Write a binary search in Python' }
]
});
console.log(response.choices[0].message.content);
console.log(response._llmshield);
// → { model: 'llama-3.3-70b-versatile', cost: 0.002, latency: 1200, cacheHit: false }Error handling
try {
const answer = await client.chat('My email is john@test.com');
} catch (err) {
if (err.status === 403) {
console.log('Blocked by guardrail:', err.details.message);
// → "Email address detected"
}
}API Reference
/v1/chat/completionsSend a chat completion request through the gateway.
Request Body
| Field | Type | Description |
|---|---|---|
messages | array | Array of message objects with role and content |
model | string? | Optional. Overrides smart routing to use a specific model. |
Success Response
{
"id": "chatcmpl-abc123",
"object": "chat.completion",
"model": "llama-3.1-8b-instant",
"choices": [{
"message": {
"role": "assistant",
"content": "Machine learning is a subset of AI..."
},
"finish_reason": "stop"
}],
"usage": {
"prompt_tokens": 43,
"completion_tokens": 30,
"total_tokens": 73
},
"_llmshield": {
"model": "llama-3.1-8b-instant",
"cost": 0.0000046,
"latency": 407,
"cacheHit": false
}
}The _llmshield block is added by the gateway with per-request metadata.
Cached Response
{
"id": "cache-1775267576857",
"choices": [{
"message": {
"role": "assistant",
"content": "Machine learning is a subset of AI..."
}
}],
"usage": { "prompt_tokens": 0, "completion_tokens": 0, "total_tokens": 0 },
"_llmshield": {
"cacheHit": true,
"latency": 1
}
}Guardrails
LLMShield scans every incoming prompt for sensitive data patterns before forwarding to the LLM. Blocked requests never reach the provider.
john@example.com555-867-53094532-1234-5678-9012123-45-6789Blocked Response
{
"error": "Request blocked by guardrail",
"details": {
"blocked": true,
"type": "email",
"message": "Email address detected"
}
}Smart Routing
The gateway automatically selects the best model based on prompt complexity.
| Condition | Model | Why |
|---|---|---|
| Short / simple prompts | llama-3.1-8b-instant | Fast, cheap, good for factual Q&A |
| Long / complex prompts | llama-3.3-70b-versatile | Powerful, better for code gen and reasoning |
Explicit model field | As specified | Override routing entirely |
Caching
The gateway normalizes each prompt (lowercase, trim whitespace) and hashes it with SHA-256. If the hash exists in Redis, the cached response is returned instantly at zero cost and sub-millisecond latency.
Configuration
Set these environment variables in the gateway's .env file.
| Variable | Default | Description |
|---|---|---|
GROQ_API_KEY | — | Your Groq API key |
DATABASE_URL | postgresql://...localhost:5432 | PostgreSQL connection string |
REDIS_URL | redis://localhost:6379 | Redis connection string |
SMALL_MODEL | llama-3.1-8b-instant | Model for short prompts |
LARGE_MODEL | llama-3.3-70b-versatile | Model for long prompts |
EMBEDDINGS_ENABLED | false | Future: vector cache toggle |