Skip to content

Commit bd221ad

Browse files
committed
feat: add custom base URL support for local AI services
Add comprehensive support for connecting to local and custom AI endpoints like LM Studio, vLLM, Ollama, and other OpenAI-compatible services. Changes: 1. Configuration options (config.yaml): - Added ai-base-url for primary provider - Added ai0-base-url through ai9-base-url for additional slots - Updated all provider descriptions with full list of 15 supported providers - Added GitHub Copilot provider support - Enhanced api-key documentation with provider-specific details 2. Config generation (hooks/common.sh): - Implemented models.providers section generation in openclaw.json - Dynamically collects custom baseUrls from primary and ai0-ai9 slots - Generates proper JSON structure only when baseUrls are configured - Handles multiple providers with different custom endpoints - Changed auth profile type from api_key to token for OpenClaw 2026.x - Removed legacy environment variable API key storage (now uses auth-profiles.json) 3. Documentation (README.md): - Added examples for LM Studio, vLLM, Text Generation WebUI - Updated Multi-AI Model Support section with baseUrl parameters - Added Using Custom Base URLs with Multiple Models section - Documented mixing cloud and local AI models simultaneously Technical details: - Research confirmed baseUrl belongs in openclaw.json at models.providers.<provider>.baseUrl - Auth-profiles.json only handles authentication (type, provider, key/token) - Supports up to 11 AI models with custom endpoints (1 primary + 10 slots) - Backward compatible - existing configs without baseUrls work unchanged Examples: - LM Studio: ai-provider=openai ai-base-url=http://localhost:1234/v1 - vLLM: ai-provider=openai ai-base-url=http://localhost:8000/v1 - Mix cloud + local: primary=anthropic, slot0=LM Studio, slot1=vLLM
1 parent 6b9dd28 commit bd221ad

3 files changed

Lines changed: 280 additions & 68 deletions

File tree

README.md

Lines changed: 73 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,34 @@ juju config openclaw \
189189
ai-model="llama3"
190190
```
191191

192+
**Local Models (LM Studio)**
193+
194+
```bash
195+
juju config openclaw \
196+
ai-provider="openai" \
197+
ai-api-key="lm-studio" \
198+
ai-model="local-model" \
199+
ai-base-url="http://localhost:1234/v1"
200+
```
201+
202+
**Other OpenAI-compatible Services**
203+
204+
```bash
205+
# vLLM
206+
juju config openclaw \
207+
ai-provider="openai" \
208+
ai-api-key="dummy-key" \
209+
ai-model="meta-llama/Llama-3.3-70B-Instruct" \
210+
ai-base-url="http://localhost:8000/v1"
211+
212+
# Text Generation WebUI
213+
juju config openclaw \
214+
ai-provider="openai" \
215+
ai-api-key="dummy-key" \
216+
ai-model="local-model" \
217+
ai-base-url="http://localhost:5000/v1"
218+
```
219+
192220
### Multi-AI Model Support
193221

194222
OpenClaw Charm supports configuring up to 11 AI models simultaneously (1 primary + 10 additional slots). This enables model switching, fallback, and specialized model usage for different tasks.
@@ -221,19 +249,50 @@ juju config openclaw \
221249

222250
**All AI Slots:**
223251

224-
- Primary: `ai-provider`, `ai-model`, `ai-api-key`
225-
- Slot 0: `ai0-provider`, `ai0-model`, `ai0-api-key`
226-
- Slot 1: `ai1-provider`, `ai1-model`, `ai1-api-key`
227-
- Slot 2: `ai2-provider`, `ai2-model`, `ai2-api-key`
228-
- Slot 3: `ai3-provider`, `ai3-model`, `ai3-api-key`
229-
- Slot 4: `ai4-provider`, `ai4-model`, `ai4-api-key`
230-
- Slot 5: `ai5-provider`, `ai5-model`, `ai5-api-key`
231-
- Slot 6: `ai6-provider`, `ai6-model`, `ai6-api-key`
232-
- Slot 7: `ai7-provider`, `ai7-model`, `ai7-api-key`
233-
- Slot 8: `ai8-provider`, `ai8-model`, `ai8-api-key`
234-
- Slot 9: `ai9-provider`, `ai9-model`, `ai9-api-key`
252+
- Primary: `ai-provider`, `ai-model`, `ai-api-key`, `ai-base-url` (optional)
253+
- Slot 0: `ai0-provider`, `ai0-model`, `ai0-api-key`, `ai0-base-url` (optional)
254+
- Slot 1: `ai1-provider`, `ai1-model`, `ai1-api-key`, `ai1-base-url` (optional)
255+
- Slot 2: `ai2-provider`, `ai2-model`, `ai2-api-key`, `ai2-base-url` (optional)
256+
- Slot 3: `ai3-provider`, `ai3-model`, `ai3-api-key`, `ai3-base-url` (optional)
257+
- Slot 4: `ai4-provider`, `ai4-model`, `ai4-api-key`, `ai4-base-url` (optional)
258+
- Slot 5: `ai5-provider`, `ai5-model`, `ai5-api-key`, `ai5-base-url` (optional)
259+
- Slot 6: `ai6-provider`, `ai6-model`, `ai6-api-key`, `ai6-base-url` (optional)
260+
- Slot 7: `ai7-provider`, `ai7-model`, `ai7-api-key`, `ai7-base-url` (optional)
261+
- Slot 8: `ai8-provider`, `ai8-model`, `ai8-api-key`, `ai8-base-url` (optional)
262+
- Slot 9: `ai9-provider`, `ai9-model`, `ai9-api-key`, `ai9-base-url` (optional)
263+
264+
**Note:** Each slot requires at minimum the three core parameters (provider, model, api-key). The `base-url` parameter is optional and only needed for custom API endpoints. Partially configured slots will trigger validation errors.
265+
266+
**Using Custom Base URLs with Multiple Models:**
267+
268+
```bash
269+
# Mix cloud and local AI models
270+
juju config openclaw \
271+
ai-provider="anthropic" \
272+
ai-api-key="sk-ant-xxx" \
273+
ai-model="claude-opus-4-5"
274+
275+
# Add LM Studio instance in slot 0
276+
juju config openclaw \
277+
ai0-provider="openai" \
278+
ai0-api-key="lm-studio" \
279+
ai0-model="local-llama3" \
280+
ai0-base-url="http://localhost:1234/v1"
281+
282+
# Add vLLM instance in slot 1
283+
juju config openclaw \
284+
ai1-provider="openai" \
285+
ai1-api-key="vllm-key" \
286+
ai1-model="meta-llama/Llama-3.3-70B-Instruct" \
287+
ai1-base-url="http://192.168.1.100:8000/v1"
288+
```
289+
290+
This configuration creates:
291+
- Primary model using Anthropic's cloud API
292+
- Slot 0 using LM Studio running locally
293+
- Slot 1 using a vLLM server on your network
235294

236-
**Note:** Each slot requires all three parameters (provider, model, api-key) to be configured. Partially configured slots will trigger validation errors.
295+
OpenClaw will generate the appropriate `models.providers` configuration in `openclaw.json` with custom baseUrls for each provider that has one specified.
237296

238297
### Messaging Channels
239298

@@ -320,9 +379,11 @@ juju config openclaw enable-browser-tool=true
320379
| `ai-provider` | string | - | AI provider: anthropic, openai, google, bedrock, ollama |
321380
| `ai-model` | string | - | AI model name |
322381
| `ai-api-key` | string | - | API key for selected provider |
382+
| `ai-base-url` | string | - | Custom API base URL (for LM Studio, vLLM, etc.) |
323383
| `ai0-provider` ... `ai9-provider` | string | - | Additional AI provider slots (0-9) |
324384
| `ai0-model` ... `ai9-model` | string | - | Additional AI model name slots (0-9) |
325385
| `ai0-api-key` ... `ai9-api-key` | string | - | Additional AI API key slots (0-9) |
386+
| `ai0-base-url` ... `ai9-base-url` | string | - | Custom API base URL for additional slots (0-9) |
326387
| `telegram-bot-token` | string | - | Telegram bot token from @BotFather |
327388
| `discord-bot-token` | string | - | Discord bot token |
328389
| `slack-bot-token` | string | - | Slack bot token (xoxb-...) |

config.yaml

Lines changed: 105 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,22 @@ options:
2323
type: string
2424
default: ""
2525
description: |
26-
Primary AI model provider: 'anthropic', 'openai', 'google', 'bedrock', or 'ollama'
26+
Primary AI model provider. Supported providers:
27+
- anthropic: Anthropic Claude models
28+
- openai: OpenAI GPT models
29+
- openai-codex: OpenAI Codex (requires OAuth)
30+
- google: Google Gemini models
31+
- opencode: OpenCode Zen models
32+
- github-copilot: GitHub Copilot/Models API
33+
- openrouter: OpenRouter aggregator
34+
- xai: xAI models
35+
- groq: Groq models
36+
- cerebras: Cerebras models
37+
- mistral: Mistral AI models
38+
- zai: Z.AI (GLM) models
39+
- vercel-ai-gateway: Vercel AI Gateway
40+
- ollama: Local Ollama models (no API key needed)
41+
- bedrock: AWS Bedrock (uses AWS credentials)
2742
2843
ai-model:
2944
type: string
@@ -34,16 +49,41 @@ options:
3449
type: string
3550
default: ""
3651
description: |
37-
API key for the selected AI provider (anthropic, openai, or google).
38-
For Anthropic: Anthropic API key
39-
For OpenAI: OpenAI API key
40-
For Google: Google Gemini API key
52+
API key for the selected AI provider. Required for most providers:
53+
- anthropic: Anthropic API key
54+
- openai: OpenAI API key
55+
- google: Google Gemini API key
56+
- opencode: OpenCode API key
57+
- github-copilot: GitHub personal access token
58+
- openrouter: OpenRouter API key
59+
- xai: xAI API key
60+
- groq: Groq API key
61+
- cerebras: Cerebras API key
62+
- mistral: Mistral API key
63+
- zai: Z.AI API key
64+
- vercel-ai-gateway: Vercel AI Gateway API key
65+
Not required for: ollama (local), bedrock (AWS credentials), openai-codex (OAuth)
66+
67+
Note: API keys are stored securely in auth-profiles.json, not in environment variables.
68+
69+
ai-base-url:
70+
type: string
71+
default: ""
72+
description: |
73+
Custom API base URL for OpenAI-compatible providers.
74+
Use this to connect to local AI services like LM Studio, vLLM, FastChat, etc.
75+
Examples:
76+
- LM Studio: http://localhost:1234/v1
77+
- vLLM: http://localhost:8000/v1
78+
- Text Generation WebUI: http://localhost:5000/v1
79+
Leave empty to use default provider endpoints.
4180
4281
# Additional AI models (ai0 through ai9) for multi-model support
4382
ai0-provider:
4483
type: string
4584
default: ""
46-
description: AI provider for model slot 0 (anthropic, openai, google, bedrock, ollama)
85+
description: |
86+
AI provider for model slot 0. See ai-provider for supported providers.
4787
4888
ai0-model:
4989
type: string
@@ -55,10 +95,15 @@ options:
5595
default: ""
5696
description: API key for AI model slot 0
5797

98+
ai0-base-url:
99+
type: string
100+
default: ""
101+
description: Custom API base URL for AI model slot 0 (for OpenAI-compatible local services)
102+
58103
ai1-provider:
59104
type: string
60105
default: ""
61-
description: AI provider for model slot 1 (anthropic, openai, google, bedrock, ollama)
106+
description: AI provider for model slot 1. See ai-provider for supported providers.
62107

63108
ai1-model:
64109
type: string
@@ -70,10 +115,15 @@ options:
70115
default: ""
71116
description: API key for AI model slot 1
72117

118+
ai1-base-url:
119+
type: string
120+
default: ""
121+
description: Custom API base URL for AI model slot 1 (for OpenAI-compatible local services)
122+
73123
ai2-provider:
74124
type: string
75125
default: ""
76-
description: AI provider for model slot 2 (anthropic, openai, google, bedrock, ollama)
126+
description: AI provider for model slot 2. See ai-provider for supported providers.
77127

78128
ai2-model:
79129
type: string
@@ -85,10 +135,15 @@ options:
85135
default: ""
86136
description: API key for AI model slot 2
87137

138+
ai2-base-url:
139+
type: string
140+
default: ""
141+
description: Custom API base URL for AI model slot 2 (for OpenAI-compatible local services)
142+
88143
ai3-provider:
89144
type: string
90145
default: ""
91-
description: AI provider for model slot 3 (anthropic, openai, google, bedrock, ollama)
146+
description: AI provider for model slot 3. See ai-provider for supported providers.
92147

93148
ai3-model:
94149
type: string
@@ -100,10 +155,15 @@ options:
100155
default: ""
101156
description: API key for AI model slot 3
102157

158+
ai3-base-url:
159+
type: string
160+
default: ""
161+
description: Custom API base URL for AI model slot 3 (for OpenAI-compatible local services)
162+
103163
ai4-provider:
104164
type: string
105165
default: ""
106-
description: AI provider for model slot 4 (anthropic, openai, google, bedrock, ollama)
166+
description: AI provider for model slot 4. See ai-provider for supported providers.
107167

108168
ai4-model:
109169
type: string
@@ -115,10 +175,15 @@ options:
115175
default: ""
116176
description: API key for AI model slot 4
117177

178+
ai4-base-url:
179+
type: string
180+
default: ""
181+
description: Custom API base URL for AI model slot 4 (for OpenAI-compatible local services)
182+
118183
ai5-provider:
119184
type: string
120185
default: ""
121-
description: AI provider for model slot 5 (anthropic, openai, google, bedrock, ollama)
186+
description: AI provider for model slot 5. See ai-provider for supported providers.
122187

123188
ai5-model:
124189
type: string
@@ -130,10 +195,15 @@ options:
130195
default: ""
131196
description: API key for AI model slot 5
132197

198+
ai5-base-url:
199+
type: string
200+
default: ""
201+
description: Custom API base URL for AI model slot 5 (for OpenAI-compatible local services)
202+
133203
ai6-provider:
134204
type: string
135205
default: ""
136-
description: AI provider for model slot 6 (anthropic, openai, google, bedrock, ollama)
206+
description: AI provider for model slot 6. See ai-provider for supported providers.
137207

138208
ai6-model:
139209
type: string
@@ -145,10 +215,15 @@ options:
145215
default: ""
146216
description: API key for AI model slot 6
147217

218+
ai6-base-url:
219+
type: string
220+
default: ""
221+
description: Custom API base URL for AI model slot 6 (for OpenAI-compatible local services)
222+
148223
ai7-provider:
149224
type: string
150225
default: ""
151-
description: AI provider for model slot 7 (anthropic, openai, google, bedrock, ollama)
226+
description: AI provider for model slot 7. See ai-provider for supported providers.
152227

153228
ai7-model:
154229
type: string
@@ -160,10 +235,15 @@ options:
160235
default: ""
161236
description: API key for AI model slot 7
162237

238+
ai7-base-url:
239+
type: string
240+
default: ""
241+
description: Custom API base URL for AI model slot 7 (for OpenAI-compatible local services)
242+
163243
ai8-provider:
164244
type: string
165245
default: ""
166-
description: AI provider for model slot 8 (anthropic, openai, google, bedrock, ollama)
246+
description: AI provider for model slot 8. See ai-provider for supported providers.
167247

168248
ai8-model:
169249
type: string
@@ -175,10 +255,15 @@ options:
175255
default: ""
176256
description: API key for AI model slot 8
177257

258+
ai8-base-url:
259+
type: string
260+
default: ""
261+
description: Custom API base URL for AI model slot 8 (for OpenAI-compatible local services)
262+
178263
ai9-provider:
179264
type: string
180265
default: ""
181-
description: AI provider for model slot 9 (anthropic, openai, google, bedrock, ollama)
266+
description: AI provider for model slot 9. See ai-provider for supported providers.
182267

183268
ai9-model:
184269
type: string
@@ -190,6 +275,11 @@ options:
190275
default: ""
191276
description: API key for AI model slot 9
192277

278+
ai9-base-url:
279+
type: string
280+
default: ""
281+
description: Custom API base URL for AI model slot 9 (for OpenAI-compatible local services)
282+
193283
telegram-bot-token:
194284
type: string
195285
default: ""

0 commit comments

Comments
 (0)