LLM Lab User Guide
LLM Lab is a unified API gateway for large language models. It provides a single OpenAI-compatible endpoint that routes your requests to the best available model based on your configuration, cost targets, and quality requirements.
Table of contents
1. Introduction
With LLM Lab, you can:
- Access multiple LLM providers through one API
- Route requests intelligently across models
- Monitor usage, costs, and latency in real time
- Manage team API keys and permissions
- Top up a prepaid wallet and control spending
This guide is for both customers (developers and teams using the API) and administrators (operators managing the platform).
2. Quick Start
- Sign Up — visit the LLM Lab web application, create an account or log in, and confirm your email if required.
- Create an API Key — navigate to API Keys in the customer portal, click Create API Key, and copy the key immediately (it is shown only once).
- Send a Request:
curl -X POST https://your-llm-lab-domain/v1/chat/completions \
-H "Authorization: Bearer YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "gpt-4o-mini",
"messages": [
{"role": "user", "content": "Hello, world!"}
]
}'
3. Authentication
LLM Lab uses API keys passed in the Authorization header.
Authorization: Bearer YOUR_API_KEY
Security best practices
- Store API keys in environment variables, never in source code
- Rotate keys regularly
- Delete keys that are no longer needed
- Use separate keys for development and production
Admin authentication
- Admins log in through the web interface
- Sessions use secure, HttpOnly, SameSite cookies
- Do not share admin credentials
4. Making Your First Request
Endpoint
POST /v1/chat/completions
Request body
{
"model": "gpt-4o-mini",
"messages": [
{"role": "system", "content": "You are a helpful assistant."},
{"role": "user", "content": "What is LLM Lab?"}
],
"temperature": 0.7,
"max_tokens": 256
}
Response
{
"id": "chatcmpl-abc123",
"object": "chat.completion",
"created": 1786123456,
"model": "gpt-4o-mini",
"choices": [
{
"index": 0,
"message": {
"role": "assistant",
"content": "LLM Lab is a unified API gateway for large language models..."
},
"finish_reason": "stop"
}
],
"usage": {
"prompt_tokens": 12,
"completion_tokens": 24,
"total_tokens": 36
}
}
Streaming
Set stream: true to receive Server-Sent Events (SSE):
{
"model": "gpt-4o-mini",
"messages": [{"role": "user", "content": "Hello"}],
"stream": true
}
5. Supported Models & Providers
LLM Lab supports multiple providers. The exact list depends on what the admin has enabled.
| Provider | Example Models |
|---|---|
| OpenAI | gpt-4o, gpt-4o-mini |
| Anthropic | claude-sonnet, claude-haiku |
| Kimi | kimi-k3, kimi-k2.7-code, kimi-k2.6 |
Listing available models
curl -H "Authorization: Bearer YOUR_API_KEY" \
https://your-llm-lab-domain/v1/models
Selecting a model
Use the model field in your request. You can use either the model alias configured in LLM Lab (e.g., gpt-4o-mini) or a Smart Model name if routing rules are configured.
6. Smart Model Routing
Smart Models let you define routing rules so requests are sent to the most appropriate model automatically.
Why use smart routing?
- Reduce costs by sending simple queries to cheaper models
- Improve quality by routing complex tasks to stronger models
- Add fallback providers for reliability
How it works
- An admin creates a Smart Model (e.g.,
smart-coding-assistant) - Rules are defined with criteria such as cost target, latency target, required capabilities, and content patterns
- Customers use the Smart Model name in their API requests
- LLM Lab selects the best matching enabled model for each request
Example request with a Smart Model
{
"model": "smart-coding-assistant",
"messages": [
{"role": "user", "content": "Write a Python function to reverse a string."}
]
}
7. Usage Dashboard
Customer dashboard
- Total requests and tokens
- Daily cost trend
- Requests over time
- Token usage over time
- Average latency trend
- Success vs. failed requests
Admin dashboard
- Platform-wide totals
- Today's revenue
- Active users and models
- Top users and top models
- Recent activity
8. Billing & Wallet
LLM Lab uses a prepaid wallet model.
Topping up
- Go to Billing in the customer portal
- Choose a top-up amount
- Complete payment through Stripe
- Your wallet balance updates immediately
Balance checks
- Each request checks your wallet balance before it is sent
- If your balance is insufficient, the API returns a
402 Payment Requiredresponse
Invoices
All top-ups and usage charges appear in the Invoices section. Download receipts for accounting purposes.
Admin billing controls
Admins can configure Stripe keys and payment settings, view all customer invoices, manage customer payment methods, and set platform-wide pricing margins.
9. API Key Management
Creating a key
- Go to API Keys
- Click Create API Key
- Enter a descriptive name (e.g., "Production Web App")
- Copy the key value immediately
Revoking a key
- Find the key in the list
- Click Delete or Revoke
- The key becomes invalid immediately
Best practices
- Use one key per application or environment
- Rotate keys every 90 days
- Monitor usage per key in the dashboard
10. Sandbox
The Sandbox is a built-in chat interface for testing models without writing code.
- Go to Sandbox
- Select a model from the dropdown
- Type a message and send
- View the model's response
Use it to test prompt behavior, compare model outputs, and validate integrations before deployment.
11. Error Handling
| Status | Meaning |
|---|---|
| 200 | Success |
| 400 | Bad request — check your JSON and parameters |
| 401 | Unauthorized — invalid or missing API key |
| 402 | Payment Required — insufficient wallet balance |
| 404 | Model not found or not available |
| 429 | Rate limit exceeded |
| 500 | Internal server error |
| 503 | Service unavailable — provider may be down |
Error response format
{
"error": {
"message": "Insufficient balance. Please top up your wallet.",
"type": "insufficient_balance"
}
}
Tips
- Always check
error.typebefore retrying - Implement exponential backoff for 429 and 503 errors
- Log request IDs when contacting support
12. Code Examples
Python
import os
from openai import OpenAI
client = OpenAI(
base_url="https://your-llm-lab-domain/v1",
api_key=os.environ["LLM_LAB_API_KEY"]
)
response = client.chat.completions.create(
model="gpt-4o-mini",
messages=[{"role": "user", "content": "Hello!"}]
)
print(response.choices[0].message.content)
Node.js
import OpenAI from 'openai';
const openai = new OpenAI({
baseURL: 'https://your-llm-lab-domain/v1',
apiKey: process.env.LLM_LAB_API_KEY,
});
const completion = await openai.chat.completions.create({
model: 'gpt-4o-mini',
messages: [{ role: 'user', content: 'Hello!' }],
});
console.log(completion.choices[0].message.content);
cURL
curl -X POST https://your-llm-lab-domain/v1/chat/completions \
-H "Authorization: Bearer $LLM_LAB_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "gpt-4o-mini",
"messages": [{"role": "user", "content": "Hello!"}]
}'
13. Admin Guide
Provider management
- Go to Admin > Providers
- Add a new provider with display name, adapter type, base URL, and encrypted API key
- Toggle providers on or off
- Run health checks from the model list
Model management
- Go to Admin > Models
- Add or edit models
- Map each model alias to an upstream provider model ID
- Set pricing (input cost per 1M tokens, output cost per 1M tokens)
- Enable or disable models for customers
Smart Model setup
- Go to Admin > Smart Models
- Create a Smart Model
- Add routing rules with priorities
- Define criteria such as cost, latency, or capabilities
- Save and test in the sandbox
User management
- Go to Admin > Users
- Create customer or admin accounts
- Reset passwords if needed
- Monitor per-user usage
Payment settings
- Go to Admin > Payment Settings
- Configure Stripe publishable and secret keys
- Set minimum top-up amount
- Enable or disable Stripe top-ups
14. Troubleshooting
- API key is invalid — verify you copied the full key, check that the key has not been revoked, and ensure the
Authorizationheader usesBearerprefix. - Model returns "not found" — confirm the model alias is enabled, check the provider is enabled, and try the exact alias shown in
/v1/models. - Insufficient balance — top up your wallet in the Billing section and check your current balance on the dashboard.
- Requests are slow — check the latency chart in the dashboard, try a different provider or model, and review Smart Model rules for latency targets.
- Provider health check fails — verify the provider API key is correct, check the provider base URL, and confirm the upstream model ID exists at the provider.
15. FAQ
Q: Is LLM Lab a replacement for OpenAI?
A: No. LLM Lab routes requests to upstream providers such as OpenAI, Anthropic, and Kimi. You still pay for upstream usage, plus the LLM Lab margin.
Q: Can I use my existing OpenAI SDK code?
A: Yes. Point the base URL to your LLM Lab domain and use your LLM Lab API key.
Q: How is pricing calculated?
A: Pricing is based on token usage and the configured per-1M-token rates for each model. A platform margin may be added.
Q: What happens if a provider is down?
A: If Smart Model fallback rules are configured, LLM Lab will route the request to an alternative provider.
Q: Can I add custom providers?
A: Yes. Admins can add custom providers that support OpenAI-compatible or Anthropic-compatible APIs.
Q: Is my data secure?
A: Provider API keys are encrypted at rest. Authentication uses secure cookies. JWTs are never exposed to client-side JavaScript.
Start building with LLM Lab
One API key. Every major model. Smart routing and real-time analytics.