Model Routing
Quick Access: Connections | Model Collections | Settings
LangMart provides flexible ways to route your API requests to the right model. Understanding model routing helps you optimize for cost, latency, and access control.
Overview
When you send a request to LangMart, the system determines which model and connection to use based on the model name format you provide:
┌─────────────────────────────────────────────────────────────────────────┐
│ Model Routing Flow │
├─────────────────────────────────────────────────────────────────────────┤
│ │
│ API Request │
│ │ │
│ ▼ │
│ ┌─────────────────────┐ │
│ │ Parse Model Name │ │
│ └──────────┬──────────┘ │
│ │ │
│ ┌─────────┼─────────────────────────────────┐ │
│ │ │ │ │ │
│ ▼ ▼ ▼ ▼ │
│ provider/ handle/ collection/ auto(free) │
│ model provider/model name │
│ │ │ │ │ │
│ ▼ ▼ ▼ ▼ │
│ Priority Direct Collection System │
│ Routing Access Strategy Collection │
│ │
└─────────────────────────────────────────────────────────────────────────┘1. Direct Model Access
The simplest way to use a model is with the standard provider/model-name format. This routes to available connections based on priority.
Format
provider/model-nameExamples
| Model Name | Description |
|---|---|
openai/gpt-4o |
OpenAI GPT-4o |
anthropic/claude-3-5-sonnet-20241022 |
Claude 3.5 Sonnet |
groq/llama-3.3-70b-versatile |
Llama 3.3 70B on Groq |
google/gemini-1.5-pro |
Google Gemini 1.5 Pro |
mistral/mistral-large-latest |
Mistral Large |
Code Example
from openai import OpenAI
client = OpenAI(
api_key="your-langmart-api-key",
base_url="https://api.langmart.ai/v1"
)
# Use direct model access
response = client.chat.completions.create(
model="groq/llama-3.3-70b-versatile",
messages=[{"role": "user", "content": "Hello!"}]
)curl -X POST https://api.langmart.ai/v1/chat/completions \
-H "Authorization: Bearer sk-langmart-..." \
-H "Content-Type: application/json" \
-d '{
"model": "openai/gpt-4o",
"messages": [{"role": "user", "content": "Hello!"}]
}'2. Priority-Based Routing
When you have the same model available from multiple connections (e.g., your private Groq key and an organization-shared Groq key), the Priority Score determines which connection is used.
How Priority Works
| Priority Score | Connection Type | Behavior |
|---|---|---|
| 100 (Highest) | Your private connections | Used first |
| 50 (Default) | Organization connections | Fallback if private unavailable |
| 0 (Lowest) | Platform defaults | Last resort |
Priority Resolution Example
Request: model="groq/llama-3.3-70b-versatile"
Available Connections:
┌────────────────────────────────────────────────────────────────┐
│ Priority 100 │ Your Private Groq Key │ ← Used first │
├────────────────────────────────────────────────────────────────┤
│ Priority 50 │ Organization Groq Key │ ← Fallback │
├────────────────────────────────────────────────────────────────┤
│ Priority 0 │ Platform Default │ ← Last resort │
└────────────────────────────────────────────────────────────────┘Customizing Priority
You can adjust connection priorities in the Connections page:
- Navigate to Connections
- Find the connection you want to adjust
- Click Edit or Priority Settings
- Set your preferred priority score (0-100)
- Save changes
Use Cases
| Scenario | Recommended Priority |
|---|---|
| Always use my own keys first | Set private connections to 100 |
| Prefer organization keys | Set org connections higher than private |
| Test platform models | Set private connections to 0 temporarily |
| Cost optimization | Prioritize connections with better rates |
3. Direct Access with LangMart Handles
LangMart Handles allow you to access specific private or organization connections directly, bypassing priority routing. This is useful when you need to ensure a request uses a particular connection.
What is a LangMart Handle?
A LangMart Handle is a unique identifier that represents you or your organization on the platform. Every user and organization has a handle that can be used for direct model routing.
| Handle Type | Format | Example | Where to Find |
|---|---|---|---|
| User Handle | Your personal LangMart identifier | john-dev |
Settings > Account |
| Organization Handle | Organization's LangMart identifier | acme-corp |
Connections page |
Finding Your LangMart Handle
- User Handle: Go to Settings > Account tab > "Your Handle" section
- Organization Handle: Go to Connections and view connection details, or check your organization settings
Handle-Based Model Format
langmart-handle/provider/model-nameExamples
| Model Name | Description |
|---|---|
john-dev/groq/llama-3.3-70b-versatile |
John's private Groq Llama model |
john-dev/openai/gpt-4o |
John's private OpenAI GPT-4o |
acme-corp/openai/gpt-4o |
Acme Corp organization's OpenAI GPT-4o |
my-startup/anthropic/claude-3-5-sonnet-20241022 |
My Startup org's Claude model |
Code Example
from openai import OpenAI
client = OpenAI(
api_key="your-langmart-api-key",
base_url="https://api.langmart.ai/v1"
)
# Use your private connection directly (user handle)
response = client.chat.completions.create(
model="john-dev/groq/llama-3.3-70b-versatile",
messages=[{"role": "user", "content": "Hello!"}]
)
# Use organization connection directly (org handle)
response = client.chat.completions.create(
model="acme-corp/openai/gpt-4o",
messages=[{"role": "user", "content": "Hello!"}]
)When to Use LangMart Handle-Based Routing
| Scenario | Benefit |
|---|---|
| Testing a specific connection | Ensure requests go to the intended API key |
| Billing separation | Route to org connection for org-paid usage |
| Compliance requirements | Ensure data goes through specific connection |
| Debugging | Isolate issues to a specific connection |
4. Model Collections
Model collections allow you to group multiple models together with a routing strategy. When you use a collection, the system automatically selects a model from the collection based on the strategy.
What is a Collection?
A collection is a named group of models with a routing strategy:
| Strategy | Description |
|---|---|
| Random | Randomly select from available models |
| Round Robin | Cycle through models in order |
| Fallback | Try models in order until one succeeds |
| Cost Optimized | Prefer lower-cost models |
| Latency Optimized | Prefer faster models |
System Collections
LangMart provides built-in system collections:
| Collection | Description |
|---|---|
auto(free) |
Free tier models with smart routing |
Collection Format
collection/collection-nameOr for system collections:
auto(free)Creating a Collection
- Navigate to Model Collections
- Click Create Collection
- Name your collection
- Add models to the collection
- Choose a routing strategy
- Save
Code Example
from openai import OpenAI
client = OpenAI(
api_key="your-langmart-api-key",
base_url="https://api.langmart.ai/v1"
)
# Use the default free collection
response = client.chat.completions.create(
model="auto(free)",
messages=[{"role": "user", "content": "Hello!"}]
)
# Use a custom collection
response = client.chat.completions.create(
model="collection/my-coding-models",
messages=[{"role": "user", "content": "Write a Python function"}]
)Example Collection: Coding Models
Collection: my-coding-models
Strategy: Fallback
Models (in order):
1. anthropic/claude-3-5-sonnet-20241022 ← Try first (best for code)
2. openai/gpt-4o ← Fallback
3. groq/llama-3.3-70b-versatile ← Last resort (fast & free)Collection Use Cases
| Use Case | Strategy | Models |
|---|---|---|
| Cost optimization | Cost Optimized | Mix of free and paid models |
| High availability | Fallback | Multiple providers for same capability |
| Load balancing | Round Robin | Same model from multiple connections |
| A/B testing | Random | Different model versions |
Routing Decision Flowchart
┌─────────────────────────────────────────────────────────────────────────┐
│ Model Name Parsing │
├─────────────────────────────────────────────────────────────────────────┤
│ │
│ Model Name Format Action │
│ ───────────────── ────── │
│ │
│ auto(free) → Use system free collection │
│ auto(*) → Use system collection │
│ │
│ collection/name → Use custom collection strategy │
│ │
│ langmart-handle/provider/model → Direct access to specific │
│ connection (user or org handle) │
│ │
│ provider/model → Priority-based routing │
│ (private → org → platform) │
│ │
└─────────────────────────────────────────────────────────────────────────┘Best Practices
1. Set Up Your LangMart Handles
Configure meaningful LangMart Handles for easy identification:
- User Handle: Your name or username (e.g.,
john,john-dev) - Organization Handle: Company name or team (e.g.,
acme-corp,my-startup)
2. Organize Connection Priorities
| Goal | Configuration |
|---|---|
| Cost control | Set org connections higher, use private for testing |
| Development | Set private connections to 100, org to 50 |
| Production | Use handle-based routing for predictability |
3. Use Collections for Resilience
Create collections with fallback strategies to ensure high availability:
Primary: openai/gpt-4o
Fallback 1: anthropic/claude-3-5-sonnet-20241022
Fallback 2: groq/llama-3.3-70b-versatile4. Monitor Routing Decisions
Check Request Logs to see which connection was used for each request:
- View the "Resolution" column for routing method
- Check "Connection" to see which API key was used
- Use filters to analyze routing patterns
Troubleshooting
Model Not Found
| Issue | Solution |
|---|---|
| Model name typo | Check exact model name in Models |
| No connection for provider | Add a connection for the provider |
| LangMart Handle doesn't exist | Verify handle in Settings or Connections |
Wrong Connection Used
| Issue | Solution |
|---|---|
| Org connection used instead of private | Increase private connection priority |
| Want specific connection | Use LangMart Handle-based routing |
| Collection picking wrong model | Check collection strategy and model order |
Access Denied
| Issue | Solution |
|---|---|
| Private model access denied | Verify you own the connection |
| Org model access denied | Check your organization membership |
| LangMart Handle not recognized | Confirm handle spelling and case |
Quick Reference
| Model Format | Example | Routing Behavior |
|---|---|---|
provider/model |
openai/gpt-4o |
Priority-based (private → org → platform) |
langmart-handle/provider/model |
john-dev/openai/gpt-4o |
Direct to user's private connection |
org-handle/provider/model |
acme-corp/openai/gpt-4o |
Direct to organization connection |
collection/name |
collection/my-models |
Collection strategy |
auto(free) |
auto(free) |
System free collection |
Related Topics
- Connections Overview - Managing provider connections
- Adding Connections - Set up new connections
- Model Collections - Creating and managing collections
- Request Logs - Monitor routing decisions