Skip to content

feat: support custom OpenAI-compatible API endpoints#2135

Merged
GermanBluefox merged 22 commits intoioBroker:masterfrom
Eistee82:master
Mar 19, 2026
Merged

feat: support custom OpenAI-compatible API endpoints#2135
GermanBluefox merged 22 commits intoioBroker:masterfrom
Eistee82:master

Conversation

@Eistee82
Copy link
Copy Markdown
Contributor

Summary

  • Add configurable base URL in adapter settings to support any OpenAI-compatible API provider (Ollama, LM Studio, Google Gemini, DeepSeek, OpenRouter, etc.)
  • Models are fetched dynamically from the configured API endpoint instead of a hardcoded list
  • Add "Test API connection" button in adapter settings (server-side via sendTo)
  • All API calls (model listing + chat completions) are proxied server-side to avoid CORS issues with local providers
  • Strip LLM thinking artifacts (<think>, <|endoftext|>, etc.) from responses for local models
  • Error handling with user-friendly messages and retry button for failed model loading
  • Translations for all new UI elements in 11 languages
  • Documentation in English and German with recommended providers (Google Gemini free tier, DeepSeek, local models)

Changes

  • src/main.ts — Add testApiConnection and chatCompletion sendTo handlers
  • src-editor/src/OpenAi/OpenAiDialog.tsx — Refactor to use server-side sendTo instead of browser-side OpenAI SDK, add dynamic model loading, error handling, response cleanup
  • admin/jsonConfig.json — Add base URL field and test connection button
  • io-package.json — Add gptBaseUrl native config
  • admin/i18n/*.json — Translations for 3 new admin UI keys (11 languages)
  • src-editor/src/i18n/*.json — Translations for 8 new editor UI keys (11 languages)
  • docs/en/README.md, docs/de/README.md — Full documentation with provider recommendations

Test plan

  • Configure OpenAI API key only (no base URL) — should work as before
  • Configure Google Gemini (base URL: https://generativelanguage.googleapis.com/v1beta/openai) — models load dynamically, code generation works
  • Configure Ollama (base URL: http://localhost:11434/v1) — models load, code generation works
  • Test "API connection test" button with valid and invalid configs
  • Test with unreachable endpoint — error message + retry button shown
  • Verify all 11 language translations render correctly in admin UI

🤖 Generated with Claude Code

Eistee82 and others added 15 commits March 17, 2026 18:31
…io, etc.)

Add configurable base URL and custom model name to allow using any
OpenAI-compatible API provider. Models are now fetched dynamically
from the configured API endpoint instead of a hardcoded list.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
… failures

Show user-friendly error messages when the API endpoint is unreachable,
API key is invalid, or model is not found. Add retry button for failed
model loading. Includes translations for all 11 languages.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
- Add sendTo handler 'testApiConnection' in main.ts for server-side
  API connectivity testing
- Add test button in admin jsonConfig using sendTo
- Add WORK IN PROGRESS changelog entry in README.md
- Add documentation for custom API support in docs/en and docs/de

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
The custom model name config field is unnecessary since available models
are now fetched dynamically from the API endpoint and shown in the
dropdown. Removed from config, i18n, dialog logic and documentation.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
The sendTo handler was only in src/main.ts but the compiled build/main.js
was missing it, causing the test button to spin indefinitely.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
- Add 'chatCompletion' sendTo handler for proxying chat requests
- Model loading already uses 'testApiConnection' sendTo handler
- Remove OpenAI SDK usage from browser (no more dangerouslyAllowBrowser)
- All API communication now goes through the adapter backend,
  which avoids CORS issues with local providers like Ollama

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
- Fix error state type from boolean to string | false
- Fix disabled prop to use !!error for boolean coercion
- Rebuild frontend assets with server-side API changes

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
The frontend build process incorrectly deleted tab.html and the custom
components directory, breaking the script editor tab. Restore original
build artifacts - source changes remain in src-editor for future builds.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
The automated build task failed on Node 25 due to deprecated rmdirSync.
Built editor with vite directly and manually copied assets + generated
tab.html with socket.io and monaco script injection.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
…requests

Local LLMs (Ollama) need Content-Length to process the request body
correctly and more time to generate responses with large prompts.
Also explicitly set stream: false for compatibility.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Local models (Ollama) often output <think> blocks, <|endoftext|> tokens,
and reasoning commentary alongside code. The response parser now:
- Strips <think>...</think> blocks
- Strips special tokens (<|endoftext|>, <|im_start|>, <|im_end|>)
- Intelligently extracts code from unstructured responses
- Removes trailing LLM commentary after code

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
…t ChatGPT

- Add Google Gemini as recommended free provider with setup instructions
- Add DeepSeek as affordable alternative
- Add guidance for local models (14B+ recommended)
- Note that free OpenAI/ChatGPT API no longer works for code generation

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Google's API returns model IDs like 'models/gemini-2.0-flash' but the
chat completions endpoint expects just 'gemini-2.0-flash'.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
- Remove old OpenAiDialog/ScriptEditor assets no longer referenced
- Update WORK IN PROGRESS changelog (remove 'custom model name',
  add server-side proxy and artifact stripping)

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@Skeletor-ai
Copy link
Copy Markdown

Bug: Empty API key rejected for local providers (Ollama, LM Studio)

When using a local provider like Ollama that doesn't require authentication, the adapter currently rejects the request with 'No API key provided' before even attempting the connection. This means the model list stays empty and no scripts can be generated.

Affected code in build/main.js (both testApiConnection and chatCompletion handlers):

if (!apiKey) {
    this.sendTo(obj.from, obj.command, { error: 'No API key provided' }, obj.callback);
    break;
}

Workaround: Users can enter any dummy string (e.g. ollama) as the API key — Ollama accepts any Bearer token value.

Suggested fix: Allow empty API key when a custom baseUrl is set (i.e. not the default OpenAI endpoint):

if (!apiKey && !baseUrl) {
    this.sendTo(obj.from, obj.command, { error: 'No API key provided' }, obj.callback);
    break;
}

Tested with Ollama http://192.168.0.141:11434/v1 — works fine with dummy key, fails silently (empty model list) when key is empty.

Eistee82 and others added 5 commits March 17, 2026 22:13
Local providers (Ollama, LM Studio) don't require authentication.
The API key check now only rejects requests when no key AND no custom
base URL is set. The Authorization header is omitted entirely when
no key is configured.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@GermanBluefox
Copy link
Copy Markdown
Contributor

@Eistee82 Have you tried Models? E.g. babbage-002 delivers: This is not a chat model and thus not supported in the v1/chat/completions endpoint. Did you mean to use v1/completions?
There are some models like sora or Dalle, the are definitely not for code generation

@GermanBluefox GermanBluefox merged commit ac4329d into ioBroker:master Mar 19, 2026
18 checks passed
@GermanBluefox
Copy link
Copy Markdown
Contributor

GermanBluefox commented Mar 19, 2026

@Eistee82 Thank you for updating AI agents. The version is now in build.
You talked about AI-Chat. Can we discuss that somehow?

@Eistee82
Copy link
Copy Markdown
Contributor Author

@Eistee82 Thank you for updating AI agents. The version is now in build. You talked about AI-Chat. Can we discuss that somehow?

https://t.me/AMEistee

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants