Skip to content

feat: run the generative roles on the local ChatGPT subscription - #251

Merged
tenphi merged 2 commits into
mainfrom
feat/chatgpt-subscription
Oct 30, 2026
Merged

tenphi merged 2 commits into
mainfrom
feat/chatgpt-subscription

Conversation

@tenphi

@tenphi tenphi commented Oct 29, 2026 •

Copy link
Copy Markdown
Owner

Summary

A provider with auth: "chatgpt" bills the ChatGPT plan Codex is signed in to on this machine instead of an API key. API keys stay the default, and the guided setup is unchanged. Luna's main model already works this way.

"providers": {
  "openai": { "base_url": "https://api.openai.com/v1", "api_key": { "env": "AKNO_OPENAI_API_KEY" }, "api": "responses" },
  "chatgpt": { "auth": "chatgpt", "fallback": "openai" }
},
"models": {
  "embedding": { "provider": "openai", "id": "text-embedding-3-small", "dimensions": 1536 },
  "reranker": { "provider": "openai", "id": "gpt-6-luna", "mode": "decisions" },
  "derive": { "provider": "chatgpt", "id": "gpt-6-luna" }
}

What the subscription serves

Probed against the Codex backend with invented prompts:

  • /responses with gpt-6-luna works, including strict JSON schema, image input, every reasoning level and max_output_tokens (with response.incomplete).
  • /decisions, /embeddings and /chat/completions return 403.
  • It requires stream: true and store: false, and it rejects temperature. It refuses models the plan doesn't offer with model_not_found.

So each role picks its provider. Roles the subscription can't serve stay on an API-key provider.

Change

  • Config (schema.ts, load.ts)
    • auth: "api_key" | "chatgpt" on a provider. With chatgpt, base_url defaults to https://chatgpt.com/backend-api/codex and api is always responses.
    • A provider that also sets api_key or another api is refused at load instead of half-applied.
    • Pointing embedding, or a decisions/endpoint reranker, at it resolves the role as unavailable, and the reason tells you to use an API-key provider.
  • Login (models/chatgpt.ts)
    • Read from $CODEX_HOME/auth.json (default ~/.codex) on every check and call; Akno never caches or refreshes it, because Codex rotates refresh tokens on use.
    • Missing, unreadable, expired or API-key logins make the subscription roles unavailable, with no request sent.
  • Transport (models/client.ts)
    • Sends stream: true, never sends temperature, and reads the streamed body down to its terminal event.
    • An error event inside a 200 surfaces as request_failed with the backend's message.
    • The access token and account id are redacted from error text.
  • Benchmarks that rebuild provider config carry auth through.
  • Docs (docs/configuration.md): a new "ChatGPT subscription" section, plus comments in default.jsonc and local.example.jsonc.
  • Changeset: minor.

Reasoning levels differ between the routes

On invented arithmetic and date checks, reasoning_effort: "low" on the subscription did no reasoning in 9 of 10 runs and got the arithmetic wrong. On the API, low reasoned and answered correctly. medium on the subscription matched the API's low. Akno sends the configured level unchanged and the docs say to re-check a role's level when moving it.

Fallback to the API (second commit)

fallback on a subscription provider names an API-key provider that serves a generative call the subscription could not. The call keeps its role, model id and settings.

  • When it falls back:
    • no usable login (the subscription isn't tried at all)
    • a refusal, or a rate or usage limit
    • a server error or an unreachable backend
    • a timeout, as long as the caller's deadline has time left
  • When it doesn't: an answer that broke its schema or language check stands. That's the model, not an outage.
  • Telemetry: the failed attempt runs unobserved, so maintenance telemetry doesn't count a call the API answered as a degraded stage.
  • Warning: every fallback reports a typed model_fallback warning (role, provider, fallback_provider, reason, message).
    • Ops run in an AsyncLocalStorage scope, and the op's result gains an optional warnings field beside an unchanged status. This covers every door: socket, MCP, HTTP and in-process.
    • The protocol version doesn't move, because the field is optional.
    • The CLI prints warnings to stderr unless --json is set.
    • An index pass lists them among its own warnings.
    • The service logs every fallback, so background work is heard. It logs once a minute per role and reason.
    • akno doctor shows a warning on roles that are falling back.
  • Config checks: Akno refuses to load a fallback on a non-subscription provider, or one naming a missing provider or another subscription.

Tests

  • New packages/core/src/models/chatgpt.test.ts (14 tests):
    • login reading and each failure state, and CODEX_HOME
    • stream collapsing
    • config defaults and refusals
    • unavailable embedding/Decisions roles and prompted reranking still available
    • the transport against a local SSE server: headers, body shape, the incomplete-then-retry path, in-stream failure, token redaction, no request without a login
  • pnpm typecheck, pnpm lint, pnpm knip, pnpm check:repository and pnpm docs:doctor pass. Prettier passes on every changed file.
  • New packages/core/src/models/model-fallback.test.ts (8 tests):
    • config rules
    • login fallback without touching the subscription
    • usage-limit fallback that observes only the call that answered
    • no fallback on success, on a contract-breaking answer, or past a caller's deadline
    • scope nesting and dedupe
    • a real recall whose expansion fell back returns the warning
  • pnpm test under Node 22: 191 files, 5,058 tests passed.
  • pnpm format:check flags packages/core/src/ops/context.ts, which this PR doesn't touch.
  • Live, through ModelClient with invented prompts, API against subscription:
    • expansion 1.7–2.0 s against 1.5–2.6 s
    • derive JSON 1.5–1.8 s against 1.3–4.1 s
    • vision 1.2 s against 1.1 s
  • akno doctor with live probes passes every role, including the answer role's generation and verification checks.

🤖 Generated with Claude Code

tenphi and others added 2 commits October 29, 2026 18:38
A provider with `auth: "chatgpt"` bills the ChatGPT plan Codex is signed in
to on this machine instead of an API key. Akno reads the login from
`$CODEX_HOME/auth.json` on every call and never refreshes it, because Codex
rotates refresh tokens on use. `base_url` defaults to the Codex backend and
`api` is always `responses`; a config that also sets `api_key` or another
transport is refused rather than half-applied.

The backend serves only streamed, stateless Responses calls and refuses
`temperature`, so these calls stream and the terminal event is read as the
response. A failure reported inside the stream surfaces with the backend's
message. Embeddings and a Decisions or endpoint reranker need endpoints the
subscription does not serve, so those roles resolve as unavailable with the
fix in the reason. A missing or expired login makes the subscription roles
unavailable without sending a request.

Benchmarks that rebuild provider config carry `auth` through. API keys stay
the default and the guided setup is unchanged.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…erve a call

`fallback` on an `auth: "chatgpt"` provider names another provider that
serves a generative call the subscription could not: no usable login, a
refusal, a rate or usage limit, a server error, an unreachable backend, or a
timeout with time left in the caller's deadline. The call keeps its role,
model id and settings. An answer that broke its contract stands, because
that is the model and not an outage. With no usable login the subscription is
not tried at all.

The failed attempt runs unobserved, so maintenance telemetry does not count a
call the fallback answered as a degraded stage.

Each fallback reports a typed `model_fallback` warning. Ops run inside a scope
that collects them, and the result gains an optional `warnings` field beside
an unchanged `status`, through every door. The protocol version does not
move, because the field is optional. The CLI prints warnings unless `--json`,
an index pass lists them with its own warnings, the service logs every
fallback (once a minute per role and reason) so background work is heard,
and `akno doctor` shows a warning on roles that are falling back.

`fallback` is refused on providers other than `auth: "chatgpt"`, and when it
names a missing provider or another subscription.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@tenphi
tenphi merged commit b3412ce into main Oct 30, 2026
5 checks passed
@github-actions github-actions Bot mentioned this pull request Oct 30, 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.

1 participant