feat: add CheapestInference provider#547
feat: add CheapestInference provider#547cheapestinference wants to merge 1 commit intosteipete:mainfrom
Conversation
API token strategy using CHEAPESTINFERENCE_API_KEY env var. Fetches budget utilization, rate limits, plan info, and credit balance from GET /v1/usage endpoint. Same sk- key used for both inference and usage monitoring. Follows the OpenRouter provider pattern (single API key, single endpoint). Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 686015fdf2
ℹ️ About Codex in GitHub
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
| case synthetic | ||
| case warp | ||
| case openrouter | ||
| case cheapestinference |
There was a problem hiding this comment.
Register new provider in descriptor bootstrap map
Adding case cheapestinference to UsageProvider without updating ProviderDescriptorRegistry.descriptorsByID introduces a startup-time crash path: bootstrap iterates UsageProvider.allCases and calls preconditionFailure when a descriptor is missing (ProviderDescriptor.swift lines 55-83), and that map still stops at .warp. Any code path that loads provider metadata/descriptors will now fail at runtime.
Useful? React with 👍 / 👎.
| public static func cheapestInferenceResolution( | ||
| environment: [String: String] = ProcessInfo.processInfo.environment) -> ProviderTokenResolution? | ||
| { | ||
| self.resolveEnv(CheapestInferenceSettingsReader.apiToken(environment: environment)) |
There was a problem hiding this comment.
Wire settings API key into CheapestInference token resolution
cheapestInferenceResolution resolves only CHEAPESTINFERENCE_API_KEY from the environment, but ProviderConfigEnvironment.applyAPIKeyOverride has no .cheapestinference branch to inject the Settings-stored API key into context.env. As a result, users who enter a key in Settings (without exporting an env var) can see the provider as available yet all fetches fail with missingToken.
Useful? React with 👍 / 👎.
Summary
api_tokenstrategyGET /v1/usagesk-inference key used for both AI requests and usage monitoringWhat is CheapestInference?
CheapestInference is a flat-rate open-source model provider. Users pay a fixed monthly subscription and get access to the best open-source models (Llama, DeepSeek, Qwen, Mistral, etc.) via OpenAI-compatible endpoints — no per-token billing surprises.
Implementation
Environment variable:
CHEAPESTINFERENCE_API_KEY(or configure in Settings)API endpoint:
GET https://api.cheapestinference.com/v1/usageResponse data mapped to CodexBar:
usedPercent(primary meter)budget.spent / budget.limit * 100windowMinutesbudget.duration(e.g. "5h" → 300)resetsAt(countdown)budget.resets_at(ISO8601)plan.slug(e.g. "Pro plan")credits.balance(e.g. "Credits: $20.00")Files added:
Sources/CodexBarCore/Providers/CheapestInference/— Descriptor, strategy, settings reader, usage fetcherSources/CodexBar/Providers/CheapestInference/— Provider implementation, settings storeSources/CodexBar/Resources/ProviderIcon-cheapestinference.svg— Provider iconFiles modified:
Sources/CodexBarCore/Providers/Providers.swift— Addedcheapestinferenceenum case + icon styleSources/CodexBarCore/Providers/ProviderTokenResolver.swift— Added token resolutionSources/CodexBarCore/Logging/LogCategories.swift— Added log categorydocs/providers.md— Added provider documentationTest plan
CHEAPESTINFERENCE_API_KEY=sk-...env varcodexbar --provider cheapestinference— should show budget meter🤖 Generated with Claude Code