Repository navigation
feat(cli): add lightning code to set up OpenCode for code.lightning.ai - #192
Merged
Merged
Conversation
`lightning code setup opencode` adds code.lightning.ai as the `lightning` provider in OpenCode's global config and creates an API key that bills the org the user picks (--org, or a numbered prompt in a terminal). Pro, Teams and Enterprise orgs are accepted; a Free org gets a link to upgrade instead. The user's config is never rewritten: the provider block is spliced into the JSONC file so comments and other settings stay byte-for-byte, and the key goes into OpenCode's auth.json (0600) rather than the config file. Re-runs reuse the key, switching org or --rotate-key replaces and revokes it, and --dry-run shows the diff. Also adds `lightning code status`, `lightning code remove opencode` (removes our entries and revokes the key) and `lightning code token` for other tools.
rusenask
requested review from
dhedey,
ethanwharris,
justusschock,
k223kim,
owbone and
tejapulagam
as code owners
October 9, 2026 10:10
… in `lightning code setup`
justusschock
approved these changes
Oct 9, 2026
dmitsf
approved these changes
Oct 9, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
Adds a
lightning codecommand group that sets up coding agents to use code.lightning.ai, starting with OpenCode:lightning code setup opencode: adds Lightning as a model provider and creates an API key that bills the chosen org.lightning code status: shows which tool is set up, with which org, key and default model.lightning code remove opencode: undoes the setup and revokes the key.lightning code token: creates a key for any other tool (Claude Code, Cursor, scripts).pi and dsh can be added later as more tools in the same flow.
Usage
Without
--org, a terminal session lists your orgs with their plans and asks which one pays. The default is the org used last time, or the first paid one. Without a terminal,--orgis required.A Free org stops with an upgrade link, and no key is created:
Other options:
Keys for other tools:
How it avoids overwriting the user's config
provider.lightningis changed. It's inserted into the globalopencode.jsoncoropencode.json(whichever OpenCode reads last) by a small JSONC editor,lightning_sdk/utils/jsonc.py. Comments, key order and the user's other settings stay byte-for-byte. The file is backed up as*.lightning-backupfirst.auth.json(mode 0600), never into the config file. This is whereopencode auth loginstores keys, and OpenCode gives it to the provider with the same id. The entry's metadata records the org and key id for re-runs,statusandremove.lightning/deepseek-v4.1-flash). It's set only if the user has no default yet, or when--modelis passed.lightningprovider the user added by hand needs--forceto be replaced, e.g. one pasted from the Coding Usage settings page with the key inline.OPENCODE_CONFIG*/OPENCODE_AUTH_CONTENT,enabled_providers/disabled_providers, and projectopencode.jsonfiles that set their ownmodelorlightningprovider.Plans and keys
GetBillingSubscription; the backend already reports a lapsed subscription as Free.disable_coding_agentsare refused.lightning api-key.--rotate-key, creates a new key and revokes the old one. If writing the files fails, the new key is revoked.Models come from
/v1/modelssetupreads the model list fromhttps://code.lightning.ai/v1/models(public, no key), using the OpenRouter-style fields added in gridai/grid#47892, so a new model shows up without a CLI release:/v1/modelsidid(lightning-ai/prefix dropped for the key)namenamelimit.contextcontext_lengthlimit.outputtop_provider.max_completion_tokens(131,072)attachment,modalities.inputarchitecture.input_modalitiestool_call/reasoningtools/reasoning_effortinsupported_parameters--modelis checked against the fetched list. An unknown model is an error that lists the served ones.max_tokens, and its compaction keeps prompts withinlimit.contextminus that. So prompt plusmax_tokensnever goes over the advertised context, and the Flash models' 400 on oversized requests can't happen from OpenCode.python/examples/code/opencode.jsonshows what setup writes on a fresh machine, from the built-in list. A test fails if the two stop matching.Docs and examples
python/examples/code_cli.rst: tutorialpython/examples/code/opencode.json,opencode-auth.json: example filespython/docs/cli/code.rst: CLI reference pageTesting
End to end in a Lightning Studio (
lightningai-engineering/skills, CPU), with this branch installed from a wheel and OpenCode 1.18.35 installed withcurl -fsSL https://opencode.ai/install | bash:setupwithout--organd without a terminal: asks for--organd lists the orgs.setup --org lightningai-engineering: creates the key, writesauth.jsonwith mode 600, andstatusreports the setup.opencode models lightninglists all 3 models.opencode auth listshows thelightningcredential.opencode run "Reply with exactly the word pong"answerspongvialightning/glm-5.3, so the key fromauth.jsonauthenticates against code.lightning.ai.setupsets"model": "lightning/deepseek-v4.1-flash", andopencode runwithout-manswerspongviadeepseek-v4.1-flash./v1/models: setup configured all 3 models with output 131,072 and image input on both Flash models, and--model gpt-9is rejected with the served list.opencode run … -f blue.png): DeepSeek V4.1 Flash and GLM-5.3 Flash both answerBlue.--model glm-5.3-flashswitches the default, andopencode runanswers viaglm-5.3-flash. The user's comments and settings survive.--rotate-keyrevokes the old key (checked withlightning api-key list), andopencode runstill works with the new key.token --jsonreturns a working key.script) lists all orgs with their plans, and its default is the org used last time.apiKeyinline) is refused without--force. With--forceit's backed up and replaced, andopencode runworks.removerestores the user's config, revokes the key, and OpenCode reportsProvider not found: lightning.Locally:
tests/cli/codeandtests/utils/test_jsonc.py(58 tests): JSONC splice and remove round-trips, parsing/v1/models(a saved copy of the live response) and falling back when it's unreachable, setup, re-run, rotate, switching org, Free plan, dry run, foreign config, invalid config, a write failure revoking the new key, status, remove, token, the org picker, and the example drift test.tests/cli/test_entrypoint.pyandtests/cli/test_non_interactive_contract.pypass.ruffandmypyare clean.🤖 Generated with Claude Code