Skip to content

fix(ai): allow OpenAI-compatible providers without an API key - #1457

Merged
NewtTheWolf merged 2 commits into
TabularisDB:mainfrom
lejyfps:fix/1323-optional-custom-openai-key
Nov 9, 2026
Merged

NewtTheWolf merged 2 commits into
TabularisDB:mainfrom
lejyfps:fix/1323-optional-custom-openai-key

Conversation

@lejyfps

@lejyfps lejyfps commented Nov 9, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #1323.

OpenAI-compatible endpoints such as local llama.cpp servers can now load their model catalog and generate responses without configuring an API key. Configured keys are still sent as Bearer tokens; requests without a key omit the Authorization header. Other providers retain their existing key requirements.

Both cached and fresh model discovery accept a missing key. The shared provider dispatcher supports keyless generation, explanation and naming requests in desktop and web.

Validation:

  • Added local HTTP regression tests for model discovery with and without authentication and generation without an Authorization header. Existing provider wire tests cover authenticated generation. Model discovery tests inject a client with proxy support explicitly disabled and a 10-second timeout, so application/system proxy settings cannot affect the loopback fixture.
  • Passed rustfmt checks and git diff --check.
  • Attempted cargo test --no-default-features --lib ai::provider_tests --offline and cargo check --no-default-features --offline. Both stop while building OpenSSL because the local Perl installation lacks Locale::Maketext::Simple; Rust tests have not run.
  • GitNexus impact and detect_changes were attempted but its native LadybugDB module fails to load. Direct callers and the two-file diff were inspected manually.

Manual verification: select OpenAI Compatible in AI settings, enter a local server URL, leave the key unset, refresh models, select a default model and generate a query. Repeat against an endpoint requiring a configured key.


Autofix with [code]smith
Open in [code]smith · Need help on this PR? Tag @codesmith-bot with what you need.

@kilo-code-bot

kilo-code-bot Bot commented Nov 9, 2026 •

Copy link
Copy Markdown
Contributor

Code Review Summary

Status: No Issues Found | Recommendation: Merge

Reviewed src-tauri/src/ai.rs and src-tauri/src/ai_provider_tests.rs at head a4a5b78. I found no bugs, security problems or regressions in the changed lines.

  • Keyless model discovery: fetch_custom_openai_models returns early only on an empty base URL. It sends a Bearer token only when a key is set.
  • Keyless generation: dispatch_provider falls back to an empty key only for custom-openai. Every other provider still propagates the missing-key error.
  • Request building: generate_custom_openai omits the Authorization header when the key is empty.
  • Since the last review: the new commit a4a5b78 splits out fetch_custom_openai_models_with_client. The discovery test now passes a no_proxy() client to it, so it no longer depends on the environment's proxy settings. This resolves the minor proxy note from the previous review. Production behavior is unchanged, because the wrapper still builds its client with ai_client_for("custom-openai"). The Client and Duration imports used by the test are already in scope.

Gaps and notes:

  • I did not run any tests. The PR description says the Rust tests could not be built locally because of an OpenSSL build issue, so they should run in CI before merge.
Files Reviewed (2 files)
  • src-tauri/src/ai.rs
  • src-tauri/src/ai_provider_tests.rs
Previous Review Summary (commit 6a246d1)

Current summary above is authoritative. Previous snapshots are kept for context only.

Previous review (commit 6a246d1)

Status: No Issues Found | Recommendation: Merge

Reviewed src-tauri/src/ai.rs and src-tauri/src/ai_provider_tests.rs at head 6a246d1. I found no bugs, security problems or regressions in the changed lines.

  • Keyless model discovery: fetch_custom_openai_models now returns early only on an empty base URL. It sends a Bearer token only when a key is set, on both the cached and fresh paths in get_models. The cached path now always overwrites the custom-openai entry, which matches the fresh path.
  • Keyless generation: dispatch_provider falls back to an empty key only for custom-openai. Every other provider still propagates the missing-key error.
  • Request building: generate_custom_openai omits the Authorization header when the key is empty.
  • Tests: the new tests cover discovery with and without a key, and generation without an Authorization header.

Gaps and notes:

  • I did not run any tests. The PR description says the Rust tests could not be built locally because of an OpenSSL build issue, so they should run in CI before merge.
  • fetch_custom_openai_models builds its client through ai_client_for("custom-openai"), which applies the configured proxy. The new discovery test uses a loopback server, so it could depend on the environment's proxy settings. This is minor and not tied to a specific changed line.
Files Reviewed (2 files)
  • src-tauri/src/ai.rs
  • src-tauri/src/ai_provider_tests.rs

Reviewed by claude-sonnet-5.5 · Input: 252 · Output: 1.5K · Cached: 191.9K

Review guidance: REVIEW.md from base branch main

@1-DARK 1-DARK left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the fix, @lejyfps! I reviewed this locally at a4a5b78.

  • I reproduced #1323 on the base commit: keyless model discovery returns [] without contacting the server, and generation sends an empty Authorization: Bearer header. On this branch, discovery returns the server's models and the header is left out when no key is set.
  • cargo test --no-default-features --lib ai::provider_tests passes 9/9 (including your two new tests), and the wider ai filter passes 343. rustfmt and clippy are clean on the touched files, and the Tauri-boundary grep is clean.
  • Other providers still require their key, and the env-var key still works.

@NewtTheWolf NewtTheWolf left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for covering both model discovery and generation while preserving authenticated requests. I reviewed a4a5b78d28a8d2d898d039356b732bc09229df72; all nine Rust provider-wire tests passed, including the local keyless discovery/generation regressions. The frontend production build and typecheck also passed.

I found no evident issue in this pass. I will verify the full settings-to-generation flow against a disposable local OpenAI-compatible server, with and without authentication, and run the full required checks before merging.

@NewtTheWolf

Copy link
Copy Markdown
Collaborator

Tested a4a5b78d28a8d2d898d039356b732bc09229df72 in the real Linux GTK/WebKitGTK app with a disposable SQLite database, local OpenAI-compatible HTTP fixture and isolated secret store. Ready to merge.

Exercised cached/fresh model discovery without a key, generated and ran a count query through AI Query Assist, and opened its AI explanation. Captured requests omitted Authorization. An auth-required fixture rejected the missing key; saving a test key through Settings restored model discovery/generation with the correct Bearer header. An unconfigured OpenAI provider still rejected the request before contacting a provider. pnpm lint && pnpm typecheck && pnpm test:all passed, including 8,654 frontend tests; GitHub checks are green. No live paid provider request was used. WebKit clipboard permission noise matches the main-branch reproduction in #1452.

@NewtTheWolf
NewtTheWolf merged commit 861e5fb into TabularisDB:main Nov 9, 2026
10 checks passed
Felixkw12 added a commit to Felixkw12/tabularis that referenced this pull request Nov 10, 2026
Resolves the conflicts with API Route (TabularisDB#1459) and the inline completion
and optional-key changes (TabularisDB#1455, TabularisDB#1457). Both providers are kept in every
list, with Opper after Requesty and API Route after Opper. In ai.rs the
Opper model fetch stays as step 7, followed by main's new custom-openai
discovery and the API Route catalog. Inline completion goes through
dispatch_provider, so it reaches Opper without further changes.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
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.

[Bug]: OpenAI compatible provider requires API key, even when not actually required by provider

3 participants