Add Ollama Cloud provider - #1173
Conversation
Tracks Ollama Cloud session and weekly limits plus recent activity spend, using the ed25519 key that `ollama signin` links to an ollama.com account — so there is no key for the user to paste and no browser session to reuse. Requests are signed the way the Ollama CLI signs them: an `Authorization: <public key>:<signature>` header over "<METHOD>,<request-uri>", where the URI carries a `ts` unix-seconds parameter so a captured header cannot be replayed. `GET /api/usage` supplies the meters and `POST /api/me` the plan name; the latter is best-effort and never blanks the meters. The meters carry no reset countdown on purpose. Ollama documents the window lengths (5 hours, 7 days) but never reports when the current window started, and a period without a reset date renders as a static "Resets in 5h" that never counts down — a real-looking countdown built from guesswork. The window lengths are documented in docs/providers/ollama.md instead. The tests build their OpenSSH key in memory rather than carrying a fixture: a committed PEM is a real private key as far as any secret scanner is concerned, throwaway or not. Generating it per run also proves a real round-trip instead of proving one frozen blob still parses. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
3895461 to
3814d24
Compare
|
lol thanks cursor |
robinebers
left a comment
There was a problem hiding this comment.
AI Review
Thanks for putting this together! Reusing the existing Ollama sign-in keeps setup simple, and leaving out reset countdowns that Ollama doesn't provide is the right call.
This looks close to shipping. I found four small fixes worth making before merge.
Small Fixes
- Make account-info failures visible. If the plan lookup fails, keep the usage meters working—but leave a useful log and a gentle warning instead of silently dropping the plan badge.
- Tighten the key check. A damaged key file can currently pass validation and then show a misleading “not signed in” message. Check that the public key sent with the request matches the signing key.
- Don't label free-of-extra-charge activity as “no usage.” A subscriber can use Ollama heavily and still have $0 additional spend. The Last 4 Weeks tooltip should not describe that as an idle period.
- Add the missing setup step. If OpenUsage checked for Ollama before it was installed, signing in later won't automatically make it appear. Tell users to enable it in Customize.
Product Choices — For the Maintainer
These are recommendations, not approved requirements:
- Start Ollama as opt-in if Cloud sign-in cannot be detected locally. Installing Ollama for local models alone shouldn't create a Cloud sign-in warning.
- Keep the proposed metric layout: Session and Weekly enabled, always visible, and pinned; Last 4 Weeks enabled, On Demand, and unpinned. Order: Session → Weekly → Last 4 Weeks.
What Was Checked
- ✅ Reviewed all 15 changed files and the related app behavior.
- ✅ Existing tests passed: 1,215 XCTest cases, 3 skipped, plus 3 Swift Testing tests.
- ✅ Additional temporary tests reproduced the three code issues above.
⚠️ Not checked with a live Ollama account or in the running app. Before shipping, compare a Pro account's meters with Ollama's dashboard and check a signed-out/local-only install.
Suggested next step: make the small fixes, confirm the product choices, then do that quick app check. No high-severity defect was found, and I wouldn't hold this for reset countdowns or extra-usage balances.
AI-assisted review of commit 3814d24.
|
This PR has been inactive for 7 days. It will be closed in 3 days unless there is new activity. If this is still relevant, please comment or push an update. |
Four fixes from the PR review. Make account-info failures visible. A failing plan lookup was indistinguishable from an account with no plan: the badge just went missing. The account call now reports why it failed, so the provider logs it and carries a warning while the meters still refresh. Tighten the key check. The outer public key is what the Authorization header carries, while the signature comes from the seed. A damaged file pairing an intact private key with a foreign public half parsed fine, then got rejected by ollama.com as "not signed in" — a dead end, since signing in again cannot fix a corrupt key file. The two halves are now checked against each other. Don't call $0.00 an idle period. The Last 4 Weeks row counts charges beyond the plan, so a subscriber can use Ollama heavily and still read $0.00. It is no longer marked as a usage period, which was giving it a "No usage in this period" hover. Document the missing setup step. Provider detection runs once, so installing Ollama after that check has already run won't switch it on; the provider page now says to enable it in Customize. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
…b' into claude/ollama-cloud-provider-5cbefb
Following the review's product recommendation: a machine with Ollama installed for local models should not get a Cloud sign-in warning. The signing key is written the first time Ollama runs, whether or not `ollama signin` ever links it to an ollama.com account, and only the network knows whether that link exists. Probing the key therefore answers "is Ollama installed?", not "is Ollama Cloud set up?", and auto-enabled the provider for every local-models user. The probe now reports no credentials, so Ollama is turned on in Customize. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
|
Thanks for the review — all four fixes are in, plus the opt-in recommendation. Small fixes
Product choices
Each fix has a regression test that fails without it. Full suite: 1,273 tests, 3 skipped, 0 failures. Also did the live check you flagged as outstanding — rebuilt and ran the app against a Pro account, and the card matches ollama.com.
Human TLDR: I got Claude to fix the issues from the AI review and made some assumptions for the product direction, but happy to realign with you @robinebers, if you would prefer it to work differently. Cheers, |
robinebers
left a comment
There was a problem hiding this comment.
The fixes and the opt-in/default-layout choices look good. The remaining warning for an unreadable plan response can be handled in a follow-up.
|
Thanks for addressing the review and checking the card against a live account. The opt-in behavior and proposed metric layout are good with me; the remaining warning edge case doesn't need to hold up this PR. Could you send a small follow-up PR for unreadable plan responses? If |
Approved issue
Fixes #1066
TL;DR
Adds Ollama Cloud as a provider: session and weekly limit meters, plus a recent activity spend row. It reuses the ed25519 key that
ollama signinalready links to the user's account, so there is no API key to paste.What was happening
docs.ollama.com/api/usage, linked from Ollama Cloud as provider #415, documents per-request timing fields such aseval_count. It is not an account usage API.What this changes
Adds
Sources/OpenUsage/Providers/Ollama/followingdocs/adding-a-provider.md: an auth store, a usage client, and a mapper conforming toProviderRuntime.Credentials. Ollama writes an ed25519 keypair to
~/.ollama/id_ed25519on first run, andollama signinlinks it to the ollama.com account. OpenUsage reads that key and signs each request the way the Ollama CLI does:The signature covers
<METHOD>,<request-uri>, where the URI carries atsunix-seconds parameter, so a captured header cannot be replayed. The private key never leaves the machine.OpenSSHEd25519Keyis a bounds-checked reader for the unencrypted OpenSSH container, scoped to what Ollama writes.Endpoints.
GET https://ollama.com/api/usagePOST https://ollama.com/api/meThe usage endpoint is undocumented and backs ollama.com/settings, so every field is read defensively.
Metrics.
Plan (Free/Pro/Max) renders as the header badge. The spend row is $0.00 on a subscription and carries real amounts for pay-as-you-go.
Also included. Registration in
ProviderCatalog(alphabetical tail, after Grok),DefaultLayout, andErrorCategory; anollama.svgprovider mark;docs/providers/ollama.md; and README entries.Heads-up
Reset countdown not supported. Ollama reports how much of each window is used but not when the current window started, so supplying the documented window lengths (5h / 7d) as
periodDurationMswould render a static "Resets in 5h" that never counts down. BothresetsAtandperiodDurationMsare therefore omitted, at the cost of Ollama's/v1/limitsentries carrying nowindowSeconds, and the cadence is documented in the provider page instead.Ollama is opt-in. The signing key exists whether or not the user has signed in, so a probe can only report that Ollama is installed, never that Cloud is set up. Rather than auto-enable and greet every local-models user with a Cloud sign-in warning,
hasLocalCredentials()returnsfalseand the user turns Ollama on in Customize. This is the one provider that deliberately does not mirrorrefresh()'s credential sources in its probe, since the local credential cannot answer the question being asked.Extra usage balance not included. The field mentioned in the issue does not appear in the response on a Pro account. It is a small addition later if someone with purchased extra usage can share their
/api/usagepayload.Provider icon.
ollama.svgcomes from Simple Icons (CC0). Its path uses SVG arc commands, whichSVGPathdoes not parse, so the arcs are converted to cubics. Rendering was verified through the app's own parser.Tests
Tests/OpenUsageTests/OllamaProviderTests.swiftcovers:usage-as-fraction conversion.limitsas a hard failure; absent meters omitted rather than shown at zero.swift buildandswift testpass on this branch rebased ontomain: 1,215 tests, 3 skipped, 0 failures. Verified end to end against a live Pro account.Screenshots
🤖 Generated with Claude Code