Skip to content

Add Moonshot provider (official platform API)#705

Closed
maxitoon wants to merge 1 commit intosteipete:mainfrom
maxitoon:feat/moonshot-provider
Closed

Add Moonshot provider (official platform API)#705
maxitoon wants to merge 1 commit intosteipete:mainfrom
maxitoon:feat/moonshot-provider

Conversation

@maxitoon
Copy link
Copy Markdown

Summary

  • add a new Moonshot provider that uses the official Moonshot balance endpoint instead of the third-party Kimi K2 service
  • support International and China regions via config/env + a settings picker
  • document the provider and add focused parser/settings/UI regression tests

Details

  • adds Sources/CodexBarCore/Providers/Moonshot/ and Sources/CodexBar/Providers/Moonshot/
  • keeps Kimi K2 untouched; this only addresses the official Moonshot provider path discussed in The Kimi K2 provider is not official and is misleading #473
  • stores Moonshot API keys in ~/.codexbar/config.json and honors MOONSHOT_API_KEY / MOONSHOT_KEY
  • honors MOONSHOT_REGION and persists a region value in provider config
  • shows Moonshot as a balance-only provider (Balance: $X.XX, No limit set) and surfaces negative cash balance as in deficit

Verification

  • swift build --target CodexBarCore
  • swift build --target CodexBarCLI
  • swift build --target CodexBarWidget
  • swift run CodexBarCLI --help (confirms moonshot is registered as a provider)
  • MOONSHOT_API_KEY=moonshot-invalid-key MOONSHOT_REGION=international swift run --skip-build CodexBarCLI usage --provider moonshot --format json (confirms a clean Moonshot API error path on invalid auth)

Environment blockers in this session

  • swift build --target CodexBar fails in the upstream KeyboardShortcuts dependency because PreviewsMacros is unavailable in this Command Line Tools-only environment
  • ./Scripts/lint.sh lint crashes inside swiftlint because SourceKit/Xcode is unavailable here
  • no real Moonshot API key was available in the environment, so I could not run the live success-path smoke test or capture screenshots

Copy link
Copy Markdown

@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: 4e626671f9

ℹ️ About Codex in GitHub

Your team has set up Codex to 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 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

guard let apiKey = Self.resolveToken(environment: context.env) else {
throw MoonshotUsageError.missingCredentials
}
let region = context.settings?.moonshot?.region ?? MoonshotSettingsReader.region(environment: context.env)
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Respect MOONSHOT_REGION when no region is configured

context.settings?.moonshot?.region takes precedence here, but this commit also makes Moonshot settings snapshots always carry a value (defaulting to .international when config omits region), so the MoonshotSettingsReader.region(environment:) fallback is effectively never used in normal app/CLI flows. In practice, users who set MOONSHOT_REGION=china (without persisting providerConfig.moonshot.region) will still call api.moonshot.ai, which breaks the documented env-based region selection path.

Useful? React with 👍 / 👎.

@steipete
Copy link
Copy Markdown
Owner

steipete commented May 8, 2026

Thanks for putting this together. I’m closing this older Moonshot PR because #793 supersedes it: that branch contains the Moonshot provider work from here and adds the Kimi CLI config discovery follow-up in the same thread. Keeping one Moonshot PR open should make review/rebase/landing much cleaner.

@steipete steipete closed this May 8, 2026
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