fix: auto-detect free API endpoint from :fx key suffix#31
Open
shirgoldbird wants to merge 8 commits intomainfrom
Open
fix: auto-detect free API endpoint from :fx key suffix#31shirgoldbird wants to merge 8 commits intomainfrom
shirgoldbird wants to merge 8 commits intomainfrom
Conversation
Add tests for isFreeApiKey() helper and URL auto-detection from API key suffix (:fx = free, otherwise = pro). These tests currently fail because the feature does not exist yet (TDD red phase). Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Free API keys (ending with :fx) require https://api-free.deepl.com but the CLI defaulted to the pro endpoint, causing 403 errors. Add isFreeApiKey() helper and use it in HttpClient to auto-detect the correct endpoint from the key suffix, matching the behavior of the official DeepL SDKs (e.g. deepl-python). Config defaults for api.baseUrl and api.usePro are now undefined, allowing auto-detection. Explicit baseUrl still overrides. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
- Add isFreeApiKey() unit tests - Add URL auto-detection tests (unit + integration) - Update existing tests to use :fx keys when mocking free API URL - Update tests that used usePro:true with free keys to use pro keys Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
init, auth set-key, and createDeepLClient were passing the config's api.baseUrl to HttpClient, which overrode auto-detection for users with old config files that had the pro URL hardcoded. - init/auth: validate new keys with auto-detected endpoint only - createDeepLClient: stop passing usePro (redundant with auto-detect) Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
The API key suffix (:fx) is the source of truth for endpoint selection, and baseUrl serves as the explicit override. usePro is redundant and has been removed from types, config, and all tests. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Persisted config files from older versions have api.baseUrl set to the pro endpoint, which overrides auto-detection for all commands. Only the --api-url CLI flag should override; otherwise let the key suffix determine the endpoint. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
- Verify auth setKey creates client without config baseUrl - Remove hardcoded api.baseUrl from translate test config object Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Free API keys (ending with
:fx) requirehttps://api-free.deepl.com, but the CLI hardcoded defaults to the pro endpoint (https://api.deepl.com), causing 403 errors for all free-tier users. This matches the auto-detection behavior of the official DeepL SDKs.Changes Made
src/api/http-client.ts: Add exportedisFreeApiKey()helper; updateHttpClientconstructor to auto-detect endpoint from key suffix (:fx→ free, otherwise → pro)src/types/config.ts: Makeapi.baseUrlandapi.useProoptionalsrc/storage/config.ts: Change defaults forapi.baseUrlandapi.useProtoundefinedso auto-detection isn't overriddenisFreeApiKey()unit tests, URL auto-detection tests (unit + integration), update existing tests to use correct key types for mocked endpointsTest Coverage
isFreeApiKey()(5 cases::fxsuffix, no suffix,:fxin middle, short keys, empty string)HttpClientURL auto-detection (free key → free URL, pro key → pro URL, explicitbaseUrloverride)DeepLClientconstructor auto-detection:fxkeys when mocking free API URLBackward Compatibility
baseUrlconfig still overrides auto-detectionapi.useProconfig key still accepted but no longer needed (key suffix is source of truth)api.baseUrlset will continue to work unchanged🤖 Generated with Claude Code