llms-py 1.0.3__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -0,0 +1,776 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: llms-py
|
|
3
|
+
Version: 1.0.3
|
|
4
|
+
Summary: A lightweight CLI tool and OpenAI-compatible server for querying multiple Large Language Model (LLM) providers
|
|
5
|
+
Home-page: https://github.com/ServiceStack/llms
|
|
6
|
+
Author: ServiceStack
|
|
7
|
+
Author-email: ServiceStack <team@servicestack.net>
|
|
8
|
+
Maintainer-email: ServiceStack <team@servicestack.net>
|
|
9
|
+
License-Expression: BSD-3-Clause
|
|
10
|
+
Project-URL: Homepage, https://github.com/ServiceStack/llms
|
|
11
|
+
Project-URL: Documentation, https://github.com/ServiceStack/llms#readme
|
|
12
|
+
Project-URL: Repository, https://github.com/ServiceStack/llms
|
|
13
|
+
Project-URL: Bug Reports, https://github.com/ServiceStack/llms/issues
|
|
14
|
+
Keywords: llm,ai,openai,anthropic,google,gemini,groq,mistral,ollama,cli,server,chat,completion
|
|
15
|
+
Classifier: Development Status :: 5 - Production/Stable
|
|
16
|
+
Classifier: Intended Audience :: Developers
|
|
17
|
+
Classifier: Intended Audience :: System Administrators
|
|
18
|
+
Classifier: Operating System :: OS Independent
|
|
19
|
+
Classifier: Programming Language :: Python :: 3
|
|
20
|
+
Classifier: Programming Language :: Python :: 3.7
|
|
21
|
+
Classifier: Programming Language :: Python :: 3.8
|
|
22
|
+
Classifier: Programming Language :: Python :: 3.9
|
|
23
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
24
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
25
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
26
|
+
Classifier: Topic :: Software Development :: Libraries :: Python Modules
|
|
27
|
+
Classifier: Topic :: Internet :: WWW/HTTP :: HTTP Servers
|
|
28
|
+
Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
|
|
29
|
+
Classifier: Topic :: System :: Systems Administration
|
|
30
|
+
Classifier: Topic :: Utilities
|
|
31
|
+
Classifier: Environment :: Console
|
|
32
|
+
Requires-Python: >=3.7
|
|
33
|
+
Description-Content-Type: text/markdown
|
|
34
|
+
License-File: LICENSE
|
|
35
|
+
Requires-Dist: aiohttp
|
|
36
|
+
Dynamic: author
|
|
37
|
+
Dynamic: home-page
|
|
38
|
+
Dynamic: license-file
|
|
39
|
+
Dynamic: requires-python
|
|
40
|
+
|
|
41
|
+
# ServiceStack LLMs
|
|
42
|
+
|
|
43
|
+
Lightweight CLI and OpenAI-compatible server for querying multiple Large Language Model (LLM) providers.
|
|
44
|
+
|
|
45
|
+
Configure additional providers and models in [llms.json](llms.json)
|
|
46
|
+
- Mix and match local models with models from different API providers
|
|
47
|
+
- Requests automatically routed to available providers that supports the requested model (in defined order)
|
|
48
|
+
- Define free/cheapest/local providers first to save on costs
|
|
49
|
+
- Any failures are automatically retried on the next available provider
|
|
50
|
+
|
|
51
|
+
## Features
|
|
52
|
+
|
|
53
|
+
- **Lightweight**: Single [llms.py](llms.py) Python file with single `aiohttp` dependency
|
|
54
|
+
- **Multi-Provider Support**: OpenRouter, Ollama, Anthropic, Google, OpenAI, Grok, Groq, Qwen, Mistral
|
|
55
|
+
- **OpenAI-Compatible API**: Works with any client that supports OpenAI's chat completion API
|
|
56
|
+
- **Configuration Management**: Easy provider enable/disable and configuration management
|
|
57
|
+
- **CLI Interface**: Simple command-line interface for quick interactions
|
|
58
|
+
- **Server Mode**: Run an OpenAI-compatible HTTP server at `http://localhost:{PORT}/v1/chat/completions`
|
|
59
|
+
- **Image Support**: Process images through vision-capable models
|
|
60
|
+
- **Audio Support**: Process audio through audio-capable models
|
|
61
|
+
- **Custom Chat Templates**: Configurable chat completion request templates for different modalities
|
|
62
|
+
- **Auto-Discovery**: Automatically discover available Ollama models
|
|
63
|
+
- **Unified Models**: Define custom model names that map to different provider-specific names
|
|
64
|
+
- **Multi-Model Support**: Support for over 160+ different LLMs
|
|
65
|
+
|
|
66
|
+
## Installation
|
|
67
|
+
|
|
68
|
+
### Option 1: Install from PyPI
|
|
69
|
+
|
|
70
|
+
```bash
|
|
71
|
+
pip install llms-py
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
### Option 2: Download directly
|
|
75
|
+
|
|
76
|
+
1. Download [llms.py](llms.py)
|
|
77
|
+
|
|
78
|
+
```bash
|
|
79
|
+
curl -O https://raw.githubusercontent.com/ServiceStack/llms/main/llms.py
|
|
80
|
+
chmod +x llms.py
|
|
81
|
+
mv llms.py ~/.local/bin/llms
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
2. Install single dependency:
|
|
85
|
+
|
|
86
|
+
```bash
|
|
87
|
+
pip install aiohttp
|
|
88
|
+
```
|
|
89
|
+
|
|
90
|
+
## Quick Start
|
|
91
|
+
|
|
92
|
+
### 1. Initialize Configuration
|
|
93
|
+
|
|
94
|
+
Create a default configuration file:
|
|
95
|
+
|
|
96
|
+
```bash
|
|
97
|
+
llms --init
|
|
98
|
+
```
|
|
99
|
+
|
|
100
|
+
This saves the latest [llms.json](llms.json) configuration to `~/.llms/llms.json`.
|
|
101
|
+
|
|
102
|
+
Modify `~/.llms/llms.json` to enable providers, add required API keys, additional models or any custom
|
|
103
|
+
OpenAI-compatible providers.
|
|
104
|
+
|
|
105
|
+
### 2. Set API Keys
|
|
106
|
+
|
|
107
|
+
Set environment variables for the providers you want to use:
|
|
108
|
+
|
|
109
|
+
```bash
|
|
110
|
+
export OPENROUTER_API_KEY="..."
|
|
111
|
+
export GROQ_API_KEY="..."
|
|
112
|
+
export GOOGLE_API_KEY="..."
|
|
113
|
+
export ANTHROPIC_API_KEY="..."
|
|
114
|
+
export GROK_API_KEY="..."
|
|
115
|
+
export DASHSCOPE_API_KEY="..."
|
|
116
|
+
# ... etc
|
|
117
|
+
```
|
|
118
|
+
|
|
119
|
+
### 3. Enable Providers
|
|
120
|
+
|
|
121
|
+
Enable the providers you want to use:
|
|
122
|
+
|
|
123
|
+
```bash
|
|
124
|
+
# Enable providers with free models and free tiers
|
|
125
|
+
llms --enable openrouter_free google_free groq
|
|
126
|
+
|
|
127
|
+
# Enable paid providers
|
|
128
|
+
llms --enable openrouter anthropic google openai mistral grok qwen
|
|
129
|
+
```
|
|
130
|
+
|
|
131
|
+
### 4. Start Chatting
|
|
132
|
+
|
|
133
|
+
```bash
|
|
134
|
+
llms "What is the capital of France?"
|
|
135
|
+
```
|
|
136
|
+
|
|
137
|
+
## Configuration
|
|
138
|
+
|
|
139
|
+
The configuration file (`llms.json`) defines available providers, models, and default settings. Key sections:
|
|
140
|
+
|
|
141
|
+
### Defaults
|
|
142
|
+
- `headers`: Common HTTP headers for all requests
|
|
143
|
+
- `text`: Default chat completion request template for text prompts
|
|
144
|
+
|
|
145
|
+
### Providers
|
|
146
|
+
|
|
147
|
+
Each provider configuration includes:
|
|
148
|
+
- `enabled`: Whether the provider is active
|
|
149
|
+
- `type`: Provider class (OpenAiProvider, GoogleProvider, etc.)
|
|
150
|
+
- `api_key`: API key (supports environment variables with `$VAR_NAME`)
|
|
151
|
+
- `base_url`: API endpoint URL
|
|
152
|
+
- `models`: Model name mappings (local name → provider name)
|
|
153
|
+
|
|
154
|
+
## Command Line Usage
|
|
155
|
+
|
|
156
|
+
### Basic Chat
|
|
157
|
+
|
|
158
|
+
```bash
|
|
159
|
+
# Simple question
|
|
160
|
+
llms "Explain quantum computing"
|
|
161
|
+
|
|
162
|
+
# With specific model
|
|
163
|
+
llms -m gemini-2.5-pro "Write a Python function to sort a list"
|
|
164
|
+
llms -m grok-4 "Explain this code with humor"
|
|
165
|
+
llms -m qwen3-max "Translate this to Chinese"
|
|
166
|
+
|
|
167
|
+
# With system prompt
|
|
168
|
+
llms -s "You are a helpful coding assistant" "How do I reverse a string in Python?"
|
|
169
|
+
|
|
170
|
+
# With image (vision models)
|
|
171
|
+
llms --image image.jpg "What's in this image?"
|
|
172
|
+
llms --image https://example.com/photo.png "Describe this photo"
|
|
173
|
+
|
|
174
|
+
# Display full JSON Response
|
|
175
|
+
llms "Explain quantum computing" --raw
|
|
176
|
+
```
|
|
177
|
+
|
|
178
|
+
### Using a Chat Template
|
|
179
|
+
|
|
180
|
+
By default llms uses the `defaults/text` chat completion request defined in [llms.json](llms.json).
|
|
181
|
+
|
|
182
|
+
You can instead use a custom chat completion request with `--chat`, e.g:
|
|
183
|
+
|
|
184
|
+
```bash
|
|
185
|
+
# Load chat completion request from JSON file
|
|
186
|
+
llms --chat request.json
|
|
187
|
+
|
|
188
|
+
# Override user message
|
|
189
|
+
llms --chat request.json "New user message"
|
|
190
|
+
|
|
191
|
+
# Override model
|
|
192
|
+
llms -m kimi-k2 --chat request.json
|
|
193
|
+
```
|
|
194
|
+
|
|
195
|
+
Example `request.json`:
|
|
196
|
+
|
|
197
|
+
```json
|
|
198
|
+
{
|
|
199
|
+
"model": "kimi-k2",
|
|
200
|
+
"messages": [
|
|
201
|
+
{"role": "system", "content": "You are a helpful assistant."},
|
|
202
|
+
{"role": "user", "content": ""}
|
|
203
|
+
],
|
|
204
|
+
"temperature": 0.7,
|
|
205
|
+
"max_tokens": 150
|
|
206
|
+
}
|
|
207
|
+
```
|
|
208
|
+
|
|
209
|
+
### Image Requests
|
|
210
|
+
|
|
211
|
+
Send images to vision-capable models using the `--image` option:
|
|
212
|
+
|
|
213
|
+
```bash
|
|
214
|
+
# Use defaults/image Chat Template (Describe the key features of the input image)
|
|
215
|
+
llms --image ./screenshot.png
|
|
216
|
+
|
|
217
|
+
# Local image file
|
|
218
|
+
llms --image ./screenshot.png "What's in this image?"
|
|
219
|
+
|
|
220
|
+
# Remote image URL
|
|
221
|
+
llms --image https://example.org/photo.jpg "Describe this photo"
|
|
222
|
+
|
|
223
|
+
# Data URI
|
|
224
|
+
llms --image "data:image/png;base64,$(base64 -w 0 image.png)" "Describe this image"
|
|
225
|
+
|
|
226
|
+
# With a specific vision model
|
|
227
|
+
llms -m gemini-2.5-flash --image chart.png "Analyze this chart"
|
|
228
|
+
llms -m qwen2.5vl --image document.jpg "Extract text from this document"
|
|
229
|
+
|
|
230
|
+
# Combined with system prompt
|
|
231
|
+
llms -s "You are a data analyst" --image graph.png "What trends do you see?"
|
|
232
|
+
|
|
233
|
+
# With custom chat template
|
|
234
|
+
llms --chat image-request.json --image photo.jpg
|
|
235
|
+
```
|
|
236
|
+
|
|
237
|
+
Example of `image-request.json`:
|
|
238
|
+
|
|
239
|
+
```json
|
|
240
|
+
{
|
|
241
|
+
"model": "qwen2.5vl",
|
|
242
|
+
"messages": [
|
|
243
|
+
{
|
|
244
|
+
"role": "user",
|
|
245
|
+
"content": [
|
|
246
|
+
{
|
|
247
|
+
"type": "image_url",
|
|
248
|
+
"image_url": {
|
|
249
|
+
"url": ""
|
|
250
|
+
}
|
|
251
|
+
},
|
|
252
|
+
{
|
|
253
|
+
"type": "text",
|
|
254
|
+
"text": "Caption this image"
|
|
255
|
+
}
|
|
256
|
+
]
|
|
257
|
+
}
|
|
258
|
+
]
|
|
259
|
+
}
|
|
260
|
+
```
|
|
261
|
+
|
|
262
|
+
**Supported image formats**: PNG, WEBP, JPG, JPEG, GIF, BMP, TIFF, ICO
|
|
263
|
+
|
|
264
|
+
**Image sources**:
|
|
265
|
+
- **Local files**: Absolute paths (`/path/to/image.jpg`) or relative paths (`./image.png`, `../image.jpg`)
|
|
266
|
+
- **Remote URLs**: HTTP/HTTPS URLs are automatically downloaded
|
|
267
|
+
- **Data URIs**: Base64-encoded images (`data:image/png;base64,...`)
|
|
268
|
+
|
|
269
|
+
Images are automatically processed and converted to base64 data URIs before being sent to the model.
|
|
270
|
+
|
|
271
|
+
### Vision-Capable Models
|
|
272
|
+
|
|
273
|
+
Popular models that support image analysis:
|
|
274
|
+
- **OpenAI**: GPT-4o, GPT-4o-mini, GPT-4.1
|
|
275
|
+
- **Anthropic**: Claude Sonnet 4.0, Claude Opus 4.1
|
|
276
|
+
- **Google**: Gemini 2.5 Pro, Gemini Flash
|
|
277
|
+
- **Qwen**: Qwen2.5-VL, Qwen3-VL, QVQ-max
|
|
278
|
+
- **Ollama**: qwen2.5vl, llava
|
|
279
|
+
|
|
280
|
+
Images are automatically downloaded and converted to base64 data URIs.
|
|
281
|
+
|
|
282
|
+
### Audio Requests
|
|
283
|
+
|
|
284
|
+
Send audio files to audio-capable models using the `--audio` option:
|
|
285
|
+
|
|
286
|
+
```bash
|
|
287
|
+
# Use defaults/audio Chat Template (Transcribe the audio)
|
|
288
|
+
llms --audio ./recording.mp3
|
|
289
|
+
|
|
290
|
+
# Local audio file
|
|
291
|
+
llms --audio ./meeting.wav "Summarize this meeting recording"
|
|
292
|
+
|
|
293
|
+
# Remote audio URL
|
|
294
|
+
llms --audio https://example.org/podcast.mp3 "What are the key points discussed?"
|
|
295
|
+
|
|
296
|
+
# With a specific audio model
|
|
297
|
+
llms -m gpt-4o-audio-preview --audio interview.mp3 "Extract the main topics"
|
|
298
|
+
llms -m gemini-2.5-flash --audio interview.mp3 "Extract the main topics"
|
|
299
|
+
|
|
300
|
+
# Combined with system prompt
|
|
301
|
+
llms -s "You're a transcription specialist" --audio talk.mp3 "Provide a detailed transcript"
|
|
302
|
+
|
|
303
|
+
# With custom chat template
|
|
304
|
+
llms --chat audio-request.json --audio speech.wav
|
|
305
|
+
```
|
|
306
|
+
|
|
307
|
+
Example of `audio-request.json`:
|
|
308
|
+
|
|
309
|
+
```json
|
|
310
|
+
{
|
|
311
|
+
"model": "gpt-4o-audio-preview",
|
|
312
|
+
"messages": [
|
|
313
|
+
{
|
|
314
|
+
"role": "user",
|
|
315
|
+
"content": [
|
|
316
|
+
{
|
|
317
|
+
"type": "input_audio",
|
|
318
|
+
"input_audio": {
|
|
319
|
+
"data": "",
|
|
320
|
+
"format": "mp3"
|
|
321
|
+
}
|
|
322
|
+
},
|
|
323
|
+
{
|
|
324
|
+
"type": "text",
|
|
325
|
+
"text": "Please transcribe this audio"
|
|
326
|
+
}
|
|
327
|
+
]
|
|
328
|
+
}
|
|
329
|
+
]
|
|
330
|
+
}
|
|
331
|
+
```
|
|
332
|
+
|
|
333
|
+
**Supported audio formats**: MP3, WAV
|
|
334
|
+
|
|
335
|
+
**Audio sources**:
|
|
336
|
+
- **Local files**: Absolute paths (`/path/to/audio.mp3`) or relative paths (`./audio.wav`, `../recording.m4a`)
|
|
337
|
+
- **Remote URLs**: HTTP/HTTPS URLs are automatically downloaded
|
|
338
|
+
- **Base64 Data**: Base64-encoded audio
|
|
339
|
+
|
|
340
|
+
Audio files are automatically processed and converted to base64 data before being sent to the model.
|
|
341
|
+
|
|
342
|
+
### Audio-Capable Models
|
|
343
|
+
|
|
344
|
+
Popular models that support audio processing:
|
|
345
|
+
- **OpenAI**: gpt-4o-audio-preview
|
|
346
|
+
- **Google**: gemini-2.5-pro, gemini-2.5-flash, gemini-2.5-flash-lite
|
|
347
|
+
|
|
348
|
+
Audio files are automatically downloaded and converted to base64 data URIs with appropriate format detection.
|
|
349
|
+
|
|
350
|
+
## Server Mode
|
|
351
|
+
|
|
352
|
+
Run as an OpenAI-compatible HTTP server:
|
|
353
|
+
|
|
354
|
+
```bash
|
|
355
|
+
# Start server on port 8000
|
|
356
|
+
llms --serve 8000
|
|
357
|
+
```
|
|
358
|
+
|
|
359
|
+
The server exposes a single endpoint:
|
|
360
|
+
- `POST /v1/chat/completions` - OpenAI-compatible chat completions
|
|
361
|
+
|
|
362
|
+
Example client usage:
|
|
363
|
+
|
|
364
|
+
```bash
|
|
365
|
+
curl -X POST http://localhost:8000/v1/chat/completions \
|
|
366
|
+
-H "Content-Type: application/json" \
|
|
367
|
+
-d '{
|
|
368
|
+
"model": "kimi-k2",
|
|
369
|
+
"messages": [
|
|
370
|
+
{"role": "user", "content": "Hello!"}
|
|
371
|
+
]
|
|
372
|
+
}'
|
|
373
|
+
```
|
|
374
|
+
|
|
375
|
+
### Configuration Management
|
|
376
|
+
|
|
377
|
+
```bash
|
|
378
|
+
# List enabled providers and models
|
|
379
|
+
llms --list
|
|
380
|
+
llms ls
|
|
381
|
+
|
|
382
|
+
# List specific providers
|
|
383
|
+
llms ls ollama
|
|
384
|
+
llms ls google anthropic
|
|
385
|
+
|
|
386
|
+
# Enable providers
|
|
387
|
+
llms --enable openrouter
|
|
388
|
+
llms --enable anthropic google_free groq
|
|
389
|
+
|
|
390
|
+
# Disable providers
|
|
391
|
+
llms --disable ollama
|
|
392
|
+
llms --disable openai anthropic
|
|
393
|
+
|
|
394
|
+
# Set default model
|
|
395
|
+
llms --default grok-4
|
|
396
|
+
```
|
|
397
|
+
|
|
398
|
+
### Update
|
|
399
|
+
|
|
400
|
+
1. Installed from PyPI
|
|
401
|
+
|
|
402
|
+
```bash
|
|
403
|
+
pip install llms-py --upgrade
|
|
404
|
+
```
|
|
405
|
+
|
|
406
|
+
2. Using Direct Download
|
|
407
|
+
|
|
408
|
+
```bash
|
|
409
|
+
# Update to latest version (Downloads latest llms.py)
|
|
410
|
+
llms --update
|
|
411
|
+
```
|
|
412
|
+
|
|
413
|
+
### Advanced Options
|
|
414
|
+
|
|
415
|
+
```bash
|
|
416
|
+
# Use custom config file
|
|
417
|
+
llms --config /path/to/config.json "Hello"
|
|
418
|
+
|
|
419
|
+
# Get raw JSON response
|
|
420
|
+
llms --raw "What is 2+2?"
|
|
421
|
+
|
|
422
|
+
# Enable verbose logging
|
|
423
|
+
llms --verbose "Tell me a joke"
|
|
424
|
+
|
|
425
|
+
# Custom log prefix
|
|
426
|
+
llms --verbose --logprefix "[DEBUG] " "Hello world"
|
|
427
|
+
|
|
428
|
+
# Set default model (updates config file)
|
|
429
|
+
llms --default grok-4
|
|
430
|
+
|
|
431
|
+
# Update llms.py to latest version
|
|
432
|
+
llms --update
|
|
433
|
+
```
|
|
434
|
+
|
|
435
|
+
### Default Model Configuration
|
|
436
|
+
|
|
437
|
+
The `--default MODEL` option allows you to set the default model used for all chat completions. This updates the `defaults.text.model` field in your configuration file:
|
|
438
|
+
|
|
439
|
+
```bash
|
|
440
|
+
# Set default model to gpt-oss
|
|
441
|
+
llms --default gpt-oss:120b
|
|
442
|
+
|
|
443
|
+
# Set default model to Claude Sonnet
|
|
444
|
+
llms --default claude-sonnet-4-0
|
|
445
|
+
|
|
446
|
+
# The model must be available in your enabled providers
|
|
447
|
+
llms --default gemini-2.5-pro
|
|
448
|
+
```
|
|
449
|
+
|
|
450
|
+
When you set a default model:
|
|
451
|
+
- The configuration file (`~/.llms/llms.json`) is automatically updated
|
|
452
|
+
- The specified model becomes the default for all future chat requests
|
|
453
|
+
- The model must exist in your currently enabled providers
|
|
454
|
+
- You can still override the default using `-m MODEL` for individual requests
|
|
455
|
+
|
|
456
|
+
### Updating llms.py
|
|
457
|
+
|
|
458
|
+
The `--update` option downloads and installs the latest version of `llms.py` from the GitHub repository:
|
|
459
|
+
|
|
460
|
+
```bash
|
|
461
|
+
# Update to latest version
|
|
462
|
+
llms --update
|
|
463
|
+
```
|
|
464
|
+
|
|
465
|
+
This command:
|
|
466
|
+
- Downloads the latest `llms.py` from `https://raw.githubusercontent.com/ServiceStack/llms/refs/heads/main/llms.py`
|
|
467
|
+
- Overwrites your current `llms.py` file with the latest version
|
|
468
|
+
- Preserves your existing configuration file (`llms.json`)
|
|
469
|
+
- Requires an internet connection to download the update
|
|
470
|
+
|
|
471
|
+
### Beautiful rendered Markdown
|
|
472
|
+
|
|
473
|
+
Pipe Markdown output to [glow](https://github.com/charmbracelet/glow) to beautifully render it in the terminal:
|
|
474
|
+
|
|
475
|
+
```bash
|
|
476
|
+
llms "Explain quantum computing" | glow
|
|
477
|
+
```
|
|
478
|
+
|
|
479
|
+
## Supported Providers
|
|
480
|
+
|
|
481
|
+
### OpenAI
|
|
482
|
+
- **Type**: `OpenAiProvider`
|
|
483
|
+
- **Models**: GPT-5, GPT-5 Codex, GPT-4o, GPT-4o-mini, o3, etc.
|
|
484
|
+
- **Features**: Text, images, function calling
|
|
485
|
+
|
|
486
|
+
```bash
|
|
487
|
+
export OPENAI_API_KEY="your-key"
|
|
488
|
+
llms --enable openai
|
|
489
|
+
```
|
|
490
|
+
|
|
491
|
+
### Anthropic (Claude)
|
|
492
|
+
- **Type**: `OpenAiProvider`
|
|
493
|
+
- **Models**: Claude Opus 4.1, Sonnet 4.0, Haiku 3.5, etc.
|
|
494
|
+
- **Features**: Text, images, large context windows
|
|
495
|
+
|
|
496
|
+
```bash
|
|
497
|
+
export ANTHROPIC_API_KEY="your-key"
|
|
498
|
+
llms --enable anthropic
|
|
499
|
+
```
|
|
500
|
+
|
|
501
|
+
### Google Gemini
|
|
502
|
+
- **Type**: `GoogleProvider`
|
|
503
|
+
- **Models**: Gemini 2.5 Pro, Flash, Flash-Lite
|
|
504
|
+
- **Features**: Text, images, safety settings
|
|
505
|
+
|
|
506
|
+
```bash
|
|
507
|
+
export GOOGLE_API_KEY="your-key"
|
|
508
|
+
llms --enable google_free
|
|
509
|
+
```
|
|
510
|
+
|
|
511
|
+
### Groq
|
|
512
|
+
- **Type**: `OpenAiProvider`
|
|
513
|
+
- **Models**: Llama 3.3, Gemma 2, Kimi K2, etc.
|
|
514
|
+
- **Features**: Fast inference, competitive pricing
|
|
515
|
+
|
|
516
|
+
```bash
|
|
517
|
+
export GROQ_API_KEY="your-key"
|
|
518
|
+
llms --enable groq
|
|
519
|
+
```
|
|
520
|
+
|
|
521
|
+
### Ollama (Local)
|
|
522
|
+
- **Type**: `OllamaProvider`
|
|
523
|
+
- **Models**: Auto-discovered from local Ollama installation
|
|
524
|
+
- **Features**: Local inference, privacy, no API costs
|
|
525
|
+
|
|
526
|
+
```bash
|
|
527
|
+
# Ollama must be running locally
|
|
528
|
+
llms --enable ollama
|
|
529
|
+
```
|
|
530
|
+
|
|
531
|
+
### OpenRouter
|
|
532
|
+
- **Type**: `OpenAiProvider`
|
|
533
|
+
- **Models**: 100+ models from various providers
|
|
534
|
+
- **Features**: Access to latest models, free tier available
|
|
535
|
+
|
|
536
|
+
```bash
|
|
537
|
+
export OPENROUTER_API_KEY="your-key"
|
|
538
|
+
llms --enable openrouter
|
|
539
|
+
```
|
|
540
|
+
|
|
541
|
+
### Mistral
|
|
542
|
+
- **Type**: `OpenAiProvider`
|
|
543
|
+
- **Models**: Mistral Large, Codestral, Pixtral, etc.
|
|
544
|
+
- **Features**: Code generation, multilingual
|
|
545
|
+
|
|
546
|
+
```bash
|
|
547
|
+
export MISTRAL_API_KEY="your-key"
|
|
548
|
+
llms --enable mistral
|
|
549
|
+
```
|
|
550
|
+
|
|
551
|
+
### Grok (X.AI)
|
|
552
|
+
- **Type**: `OpenAiProvider`
|
|
553
|
+
- **Models**: Grok-4, Grok-3, Grok-3-mini, Grok-code-fast-1, etc.
|
|
554
|
+
- **Features**: Real-time information, humor, uncensored responses
|
|
555
|
+
|
|
556
|
+
```bash
|
|
557
|
+
export GROK_API_KEY="your-key"
|
|
558
|
+
llms --enable grok
|
|
559
|
+
```
|
|
560
|
+
|
|
561
|
+
### Qwen (Alibaba Cloud)
|
|
562
|
+
- **Type**: `OpenAiProvider`
|
|
563
|
+
- **Models**: Qwen3-max, Qwen-max, Qwen-plus, Qwen2.5-VL, QwQ-plus, etc.
|
|
564
|
+
- **Features**: Multilingual, vision models, coding, reasoning, audio processing
|
|
565
|
+
|
|
566
|
+
```bash
|
|
567
|
+
export DASHSCOPE_API_KEY="your-key"
|
|
568
|
+
llms --enable qwen
|
|
569
|
+
```
|
|
570
|
+
|
|
571
|
+
## Model Routing
|
|
572
|
+
|
|
573
|
+
The tool automatically routes requests to the first available provider that supports the requested model. If a provider fails, it tries the next available provider with that model.
|
|
574
|
+
|
|
575
|
+
Example: If both OpenAI and OpenRouter support `kimi-k2`, the request will first try OpenRouter (free), then fall back to Groq than OpenRouter (Paid) if requests fails.
|
|
576
|
+
|
|
577
|
+
## Environment Variables
|
|
578
|
+
|
|
579
|
+
| Variable | Description | Example |
|
|
580
|
+
|----------|-------------|---------|
|
|
581
|
+
| `LLMS_CONFIG_PATH` | Custom config file path | `/path/to/llms.json` |
|
|
582
|
+
| `OPENAI_API_KEY` | OpenAI API key | `sk-...` |
|
|
583
|
+
| `ANTHROPIC_API_KEY` | Anthropic API key | `sk-ant-...` |
|
|
584
|
+
| `GOOGLE_API_KEY` | Google API key | `AIza...` |
|
|
585
|
+
| `GROQ_API_KEY` | Groq API key | `gsk_...` |
|
|
586
|
+
| `MISTRAL_API_KEY` | Mistral API key | `...` |
|
|
587
|
+
| `OPENROUTER_API_KEY` | OpenRouter API key | `sk-or-...` |
|
|
588
|
+
| `OPENROUTER_FREE_API_KEY` | OpenRouter free tier key | `sk-or-...` |
|
|
589
|
+
| `CODESTRAL_API_KEY` | Codestral API key | `...` |
|
|
590
|
+
| `GROK_API_KEY` | Grok (X.AI) API key | `xai-...` |
|
|
591
|
+
| `DASHSCOPE_API_KEY` | Qwen (Alibaba Cloud) API key | `sk-...` |
|
|
592
|
+
|
|
593
|
+
## Configuration Examples
|
|
594
|
+
|
|
595
|
+
### Minimal Configuration
|
|
596
|
+
|
|
597
|
+
```json
|
|
598
|
+
{
|
|
599
|
+
"defaults": {
|
|
600
|
+
"headers": {"Content-Type": "application/json"},
|
|
601
|
+
"text": {
|
|
602
|
+
"model": "kimi-k2",
|
|
603
|
+
"messages": [{"role": "user", "content": ""}]
|
|
604
|
+
}
|
|
605
|
+
},
|
|
606
|
+
"providers": {
|
|
607
|
+
"groq": {
|
|
608
|
+
"enabled": true,
|
|
609
|
+
"type": "OpenAiProvider",
|
|
610
|
+
"base_url": "https://api.groq.com/openai",
|
|
611
|
+
"api_key": "$GROQ_API_KEY",
|
|
612
|
+
"models": {
|
|
613
|
+
"llama3.3:70b": "llama-3.3-70b-versatile",
|
|
614
|
+
"llama4:109b": "meta-llama/llama-4-scout-17b-16e-instruct",
|
|
615
|
+
"llama4:400b": "meta-llama/llama-4-maverick-17b-128e-instruct",
|
|
616
|
+
"kimi-k2": "moonshotai/kimi-k2-instruct-0905",
|
|
617
|
+
"gpt-oss:120b": "openai/gpt-oss-120b",
|
|
618
|
+
"gpt-oss:20b": "openai/gpt-oss-20b",
|
|
619
|
+
"qwen3:32b": "qwen/qwen3-32b"
|
|
620
|
+
}
|
|
621
|
+
}
|
|
622
|
+
}
|
|
623
|
+
}
|
|
624
|
+
```
|
|
625
|
+
|
|
626
|
+
### Multi-Provider Setup
|
|
627
|
+
|
|
628
|
+
```json
|
|
629
|
+
{
|
|
630
|
+
"providers": {
|
|
631
|
+
"openrouter": {
|
|
632
|
+
"enabled": false,
|
|
633
|
+
"type": "OpenAiProvider",
|
|
634
|
+
"base_url": "https://openrouter.ai/api",
|
|
635
|
+
"api_key": "$OPENROUTER_API_KEY",
|
|
636
|
+
"models": {
|
|
637
|
+
"grok-4": "x-ai/grok-4",
|
|
638
|
+
"glm-4.5-air": "z-ai/glm-4.5-air",
|
|
639
|
+
"kimi-k2": "moonshotai/kimi-k2",
|
|
640
|
+
"deepseek-v3.1:671b": "deepseek/deepseek-chat",
|
|
641
|
+
"llama4:400b": "meta-llama/llama-4-maverick"
|
|
642
|
+
}
|
|
643
|
+
},
|
|
644
|
+
"anthropic": {
|
|
645
|
+
"enabled": false,
|
|
646
|
+
"type": "OpenAiProvider",
|
|
647
|
+
"base_url": "https://api.anthropic.com",
|
|
648
|
+
"api_key": "$ANTHROPIC_API_KEY",
|
|
649
|
+
"models": {
|
|
650
|
+
"claude-sonnet-4-0": "claude-sonnet-4-0"
|
|
651
|
+
}
|
|
652
|
+
},
|
|
653
|
+
"ollama": {
|
|
654
|
+
"enabled": false,
|
|
655
|
+
"type": "OllamaProvider",
|
|
656
|
+
"base_url": "http://localhost:11434",
|
|
657
|
+
"models": {},
|
|
658
|
+
"all_models": true
|
|
659
|
+
}
|
|
660
|
+
}
|
|
661
|
+
}
|
|
662
|
+
```
|
|
663
|
+
|
|
664
|
+
## Usage
|
|
665
|
+
|
|
666
|
+
Run `llms` without arguments to see the help screen:
|
|
667
|
+
|
|
668
|
+
usage: llms.py [-h] [--config FILE] [-m MODEL] [--chat REQUEST] [-s PROMPT] [--image IMAGE] [--audio AUDIO]
|
|
669
|
+
[--file FILE] [--raw] [--list] [--serve PORT] [--enable PROVIDER] [--disable PROVIDER]
|
|
670
|
+
[--default MODEL] [--init] [--logprefix PREFIX] [--verbose] [--update]
|
|
671
|
+
|
|
672
|
+
llms
|
|
673
|
+
|
|
674
|
+
options:
|
|
675
|
+
-h, --help show this help message and exit
|
|
676
|
+
--config FILE Path to config file
|
|
677
|
+
-m MODEL, --model MODEL
|
|
678
|
+
Model to use
|
|
679
|
+
--chat REQUEST OpenAI Chat Completion Request to send
|
|
680
|
+
-s PROMPT, --system PROMPT
|
|
681
|
+
System prompt to use for chat completion
|
|
682
|
+
--image IMAGE Image input to use in chat completion
|
|
683
|
+
--audio AUDIO Audio input to use in chat completion
|
|
684
|
+
--file FILE File input to use in chat completion
|
|
685
|
+
--raw Return raw AI JSON response
|
|
686
|
+
--list Show list of enabled providers and their models (alias ls provider?)
|
|
687
|
+
--serve PORT Port to start an OpenAI Chat compatible server on
|
|
688
|
+
--enable PROVIDER Enable a provider
|
|
689
|
+
--disable PROVIDER Disable a provider
|
|
690
|
+
--default MODEL Configure the default model to use
|
|
691
|
+
--init Create a default llms.json
|
|
692
|
+
--logprefix PREFIX Prefix used in log messages
|
|
693
|
+
--verbose Verbose output
|
|
694
|
+
--update Update to latest version
|
|
695
|
+
|
|
696
|
+
## Troubleshooting
|
|
697
|
+
|
|
698
|
+
### Common Issues
|
|
699
|
+
|
|
700
|
+
**Config file not found**
|
|
701
|
+
```bash
|
|
702
|
+
# Initialize default config
|
|
703
|
+
llms --init
|
|
704
|
+
|
|
705
|
+
# Or specify custom path
|
|
706
|
+
llms --config ./my-config.json
|
|
707
|
+
```
|
|
708
|
+
|
|
709
|
+
**No providers enabled**
|
|
710
|
+
|
|
711
|
+
```bash
|
|
712
|
+
# Check status
|
|
713
|
+
llms --list
|
|
714
|
+
|
|
715
|
+
# Enable providers
|
|
716
|
+
llms --enable google anthropic
|
|
717
|
+
```
|
|
718
|
+
|
|
719
|
+
**API key issues**
|
|
720
|
+
```bash
|
|
721
|
+
# Check environment variables
|
|
722
|
+
echo $ANTHROPIC_API_KEY
|
|
723
|
+
|
|
724
|
+
# Enable verbose logging
|
|
725
|
+
llms --verbose "test"
|
|
726
|
+
```
|
|
727
|
+
|
|
728
|
+
**Model not found**
|
|
729
|
+
|
|
730
|
+
```bash
|
|
731
|
+
# List available models
|
|
732
|
+
llms --list
|
|
733
|
+
|
|
734
|
+
# Check provider configuration
|
|
735
|
+
llms ls openrouter
|
|
736
|
+
```
|
|
737
|
+
|
|
738
|
+
### Debug Mode
|
|
739
|
+
|
|
740
|
+
Enable verbose logging to see detailed request/response information:
|
|
741
|
+
|
|
742
|
+
```bash
|
|
743
|
+
llms --verbose --logprefix "[DEBUG] " "Hello"
|
|
744
|
+
```
|
|
745
|
+
|
|
746
|
+
This shows:
|
|
747
|
+
- Enabled providers
|
|
748
|
+
- Model routing decisions
|
|
749
|
+
- HTTP request details
|
|
750
|
+
- Error messages with stack traces
|
|
751
|
+
|
|
752
|
+
## Development
|
|
753
|
+
|
|
754
|
+
### Project Structure
|
|
755
|
+
|
|
756
|
+
- `llms.py` - Main script with CLI and server functionality
|
|
757
|
+
- `llms.json` - Default configuration file
|
|
758
|
+
- `requirements.txt` - Python dependencies
|
|
759
|
+
|
|
760
|
+
### Provider Classes
|
|
761
|
+
|
|
762
|
+
- `OpenAiProvider` - Generic OpenAI-compatible provider
|
|
763
|
+
- `OllamaProvider` - Ollama-specific provider with model auto-discovery
|
|
764
|
+
- `GoogleProvider` - Google Gemini with native API format
|
|
765
|
+
- `GoogleOpenAiProvider` - Google Gemini via OpenAI-compatible endpoint
|
|
766
|
+
|
|
767
|
+
### Adding New Providers
|
|
768
|
+
|
|
769
|
+
1. Create a provider class inheriting from `OpenAiProvider`
|
|
770
|
+
2. Implement provider-specific authentication and formatting
|
|
771
|
+
3. Add provider configuration to `llms.json`
|
|
772
|
+
4. Update initialization logic in `init_llms()`
|
|
773
|
+
|
|
774
|
+
## Contributing
|
|
775
|
+
|
|
776
|
+
Contributions are welcome! Please submit a PR to add support for any missing OpenAI-compatible providers.
|