Skip to content

feat: add CheapestInference provider#547

Open
cheapestinference wants to merge 1 commit intosteipete:mainfrom
cheapestinference:add-cheapestinference-provider
Open

feat: add CheapestInference provider#547
cheapestinference wants to merge 1 commit intosteipete:mainfrom
cheapestinference:add-cheapestinference-provider

Conversation

@cheapestinference
Copy link

@cheapestinference cheapestinference commented Mar 16, 2026

Summary

  • Adds CheapestInference as a new provider using the api_token strategy
  • Fetches budget utilization, rate limits, plan info, and credit balance from GET /v1/usage
  • Same sk- inference key used for both AI requests and usage monitoring
  • Follows the OpenRouter provider pattern (single API key, single endpoint)

What 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/usage

Response data mapped to CodexBar:

CodexBar field Source
usedPercent (primary meter) budget.spent / budget.limit * 100
windowMinutes Parsed from budget.duration (e.g. "5h" → 300)
resetsAt (countdown) budget.resets_at (ISO8601)
Identity: organization plan.slug (e.g. "Pro plan")
Identity: loginMethod credits.balance (e.g. "Credits: $20.00")

Files added:

  • Sources/CodexBarCore/Providers/CheapestInference/ — Descriptor, strategy, settings reader, usage fetcher
  • Sources/CodexBar/Providers/CheapestInference/ — Provider implementation, settings store
  • Sources/CodexBar/Resources/ProviderIcon-cheapestinference.svg — Provider icon

Files modified:

  • Sources/CodexBarCore/Providers/Providers.swift — Added cheapestinference enum case + icon style
  • Sources/CodexBarCore/Providers/ProviderTokenResolver.swift — Added token resolution
  • Sources/CodexBarCore/Logging/LogCategories.swift — Added log category
  • docs/providers.md — Added provider documentation

Test plan

  • Set CHEAPESTINFERENCE_API_KEY=sk-... env var
  • Run codexbar --provider cheapestinference — should show budget meter
  • Verify Settings UI shows API key field
  • Test with invalid key — should show auth error
  • Test without key — provider should show as unavailable

🤖 Generated with Claude Code

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>
Copy link

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

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

💡 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

Choose a reason for hiding this comment

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

P0 Badge 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))

Choose a reason for hiding this comment

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

P1 Badge 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 👍 / 👎.

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