Skip to content

fix: auto-detect free API endpoint from :fx key suffix#31

Open
shirgoldbird wants to merge 8 commits intomainfrom
fix/free-api-key-autodetect
Open

fix: auto-detect free API endpoint from :fx key suffix#31
shirgoldbird wants to merge 8 commits intomainfrom
fix/free-api-key-autodetect

Conversation

@shirgoldbird
Copy link
Copy Markdown
Member

Summary

Free API keys (ending with :fx) require https://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 exported isFreeApiKey() helper; update HttpClient constructor to auto-detect endpoint from key suffix (:fx → free, otherwise → pro)
  • src/types/config.ts: Make api.baseUrl and api.usePro optional
  • src/storage/config.ts: Change defaults for api.baseUrl and api.usePro to undefined so auto-detection isn't overridden
  • Tests: Add isFreeApiKey() unit tests, URL auto-detection tests (unit + integration), update existing tests to use correct key types for mocked endpoints

Test Coverage

  • Unit tests for isFreeApiKey() (5 cases: :fx suffix, no suffix, :fx in middle, short keys, empty string)
  • Unit tests for HttpClient URL auto-detection (free key → free URL, pro key → pro URL, explicit baseUrl override)
  • Integration tests for DeepLClient constructor auto-detection
  • All existing tests updated to use :fx keys when mocking free API URL

Backward Compatibility

  • Explicit baseUrl config still overrides auto-detection
  • api.usePro config key still accepted but no longer needed (key suffix is source of truth)
  • Existing user configs with explicit api.baseUrl set will continue to work unchanged

🤖 Generated with Claude Code

shirgoldbird and others added 8 commits March 31, 2026 16:07
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>
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.

1 participant