Skip to content

add support for 3rd party API's besides OpenRouter - #17

Open
SellPL wants to merge 4 commits into
riki137:mainfrom
SellPL:my-feature-branch
Open

add support for 3rd party API's besides OpenRouter#17
SellPL wants to merge 4 commits into
riki137:mainfrom
SellPL:my-feature-branch

Conversation

@SellPL

@SellPL SellPL commented Jul 25, 2026

Copy link
Copy Markdown

this pull request adds support for other API's. Worked for me on android with 3rd party provider with claude opus 5 model. more from Claude Fable 5 about this since it was vibecoded:
PR notes:
▎ Add Anthropic (Claude) as a selectable AI provider

▎ Anthropic speaks its own Messages API rather than OpenAI chat completions, so this adds a small protocol discriminator instead of pretending it's another base URL:
▎ - New AiApiProtocol enum; provider registry entry for Anthropic (/v1/messages, key hint sk-ant-..., suggested model claude-opus-5).
▎ - AIService branches per protocol: x-api-key + anthropic-version: 2023-06-01 headers, system prompt moved to top-level system, required max_tokens (2048), OpenAI-style data-URL images converted to base64
▎ image content blocks, reply text taken from the first content[].text block.
▎ - No response_format on Anthropic — relies on the existing strict-JSON prompt and the lenient parseModelJson recovery, unchanged.
▎ - anthropic-dangerous-direct-browser-access: true header so the web build works (BYO-key in browser is already this app's model on every provider).
▎ - Settings UI picks the provider up automatically from kAiProviders; public AIService API unchanged, so no caller edits. README/settings copy updated; unit test added for endpoint/protocol resolution.

▎ Tested: flutter analyze clean, full test suite passes, web + Android release builds compile. Not tested: live calls against the Anthropic API (no key available) — request/response shapes follow current
▎ Messages API docs and want one manual verification.
Screenshot_20260725_134920
Screenshot_20260725_134949

@SellPL
SellPL marked this pull request as draft July 25, 2026 10:58
@SellPL
SellPL marked this pull request as ready for review July 25, 2026 11:06

@riki137 riki137 left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Thanks for the contribution. The protocol-discriminator approach makes sense, and the Anthropic request shape broadly matches the Messages API. However, this branch is not merge-ready; there are clear signs the generated changes were not properly reviewed.

  • The history commits a 66.9 MB APK, the complete web build, and node_modules, then deletes them later. Please rewrite/squash the branch before a merge/rebase so these blobs do not enter the repository history.
  • The final diff still contains unrelated package.json and package-lock.json files with an unused git npm dependency. These should be removed. Please also revert or explain the unrelated android/gradle.properties and pubspec.lock changes.
  • .gitignore:56-57 contains "node_modules/" and "dist/". Git treats those quotes literally, so the directories are not ignored. Use node_modules/ and dist/ without quotes and clean up the trailing whitespace/line endings.
  • Switching from another free-text provider to Anthropic retains the previous model and fallback values: updateProvider() only changes the provider ID. For example, switching from OpenAI with gpt-5.5 and saving will send gpt-5.5 to the Anthropic endpoint. Provider changes need to reset or populate the model fields, with a regression test.
  • The added test only checks endpoint/protocol resolution. None of the important new behavior is exercised: Anthropic headers, top-level system, image conversion, omission of response_format, or response parsing. Please make HTTP injectable/mockable and test the actual outbound request and representative responses.
  • AIService ignores Anthropic’s stop_reason and attempts to parse every HTTP 200 text block as food JSON. max_tokens, refusal, and context-limit responses need explicit handling. This matters particularly because Claude Opus 5 enables thinking by default and thinking counts against the hardcoded 2,048-token ceiling. Anthropic recommends always checking stop_reason: stop-reason documentation, thinking documentation.

I ran the complete Flutter test suite against commit d59b062; it passes. The core idea is usable, but the branch hygiene and missing protocol-level tests need fixing before merge.

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.

2 participants