Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions python/docs/cli/code.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
Code
++++

.. lightning-reference:: code
:root-label: lightning code
:anchor-prefix: code

from lightning_sdk.cli.groups import code
2 changes: 2 additions & 0 deletions python/docs/cli/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ Common Workflows
* Configure accounts, organizations, teamspaces, cloud accounts, and SSH with
:doc:`config`, :doc:`api-key`, and :doc:`ssh`.
* Manage lower-level sandbox sessions with :doc:`sandbox`.
* Point coding agents such as OpenCode at code.lightning.ai with :doc:`code`.

Command details
---------------
Expand All @@ -124,3 +125,4 @@ reference.
base-studio
license
cp
code
1 change: 1 addition & 0 deletions python/examples/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ export LIGHTNING_SANDBOX_API_KEY="..."
| [`sandboxes_cli.rst`](sandboxes_cli.rst) | Create sandboxes, run commands, inspect logs, stop, resume, and delete from the CLI |
| [`logs_cli.rst`](logs_cli.rst) | Tail, follow, search, and page logs for jobs, MMTs, deployments, and sandboxes |
| [`api_cli.rst`](api_cli.rst) | Call authenticated Lightning API endpoints directly from shell scripts |
| [`code_cli.rst`](code_cli.rst) | Set up OpenCode for code.lightning.ai and create keys for other coding tools |

# Running examples

Expand Down
13 changes: 13 additions & 0 deletions python/examples/code/opencode-auth.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"lightning": {
"type": "api",
"key": "sk-lit-replace-me",
"metadata": {
"managed_by": "lightning-sdk",
"org_id": "01jexample0rg0000000000000",
"org_name": "my-org",
"key_id": "01jexamplekey0000000000000",
"key_name": "opencode on my-laptop 2026-10-09"
}
}
}
69 changes: 69 additions & 0 deletions python/examples/code/opencode.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
{
"$schema": "https://opencode.ai/config.json",
"provider": {
"lightning": {
"npm": "@ai-sdk/openai-compatible",
"name": "Lightning AI",
"options": {
"baseURL": "https://code.lightning.ai/v1",
"timeout": 600000
},
"models": {
"glm-5.3": {
"id": "lightning-ai/glm-5.3",
"name": "GLM-5.3",
"reasoning": true,
"interleaved": "reasoning_content",
"tool_call": true,
"limit": {
"context": 1048576,
"output": 131072
}
},
"glm-5.3-flash": {
"id": "lightning-ai/glm-5.3-flash",
"name": "GLM-5.3 Flash",
"reasoning": true,
"interleaved": "reasoning_content",
"tool_call": true,
"attachment": true,
"modalities": {
"input": [
"text",
"image"
],
"output": [
"text"
]
},
"limit": {
"context": 253952,
"output": 131072
}
},
"deepseek-v4.1-flash": {
"id": "lightning-ai/deepseek-v4.1-flash",
"name": "DeepSeek V4.1 Flash",
"reasoning": true,
"interleaved": "reasoning_content",
"tool_call": true,
"attachment": true,
"modalities": {
"input": [
"text",
"image"
],
"output": [
"text"
]
},
"limit": {
"context": 253952,
"output": 131072
}
}
}
}
},
"model": "lightning/deepseek-v4.1-flash"
}
90 changes: 90 additions & 0 deletions python/examples/code_cli.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
Coding agents CLI examples
==========================

`code.lightning.ai <https://code.lightning.ai>`_ serves GLM-5.3, GLM-5.3 Flash and
DeepSeek V4.1 Flash to coding agents through an OpenAI-compatible API at
``https://code.lightning.ai/v1``. The ``lightning code`` commands set up a coding
tool to use it and create the API key it needs.

Requests bill the organization you pick, which needs a Pro, Teams or Enterprise
plan. A Free organization gets a link to upgrade instead of a key.

Set up OpenCode
---------------

.. code-block:: console

$ pip install lightning-sdk -U
$ lightning login
$ curl -fsSL https://opencode.ai/install | bash

$ lightning code setup opencode --org my-org
OpenCode now uses code.lightning.ai, billed to My Org [my-org].
Provider: lightning in ~/.config/opencode/opencode.json
API key: opencode on my-laptop 2026-10-09 in ~/.local/share/opencode/auth.json
Default: lightning/deepseek-v4.1-flash

$ opencode

Without ``--org``, the command lists your organizations with their plans and asks
which one pays. In scripts and other non-interactive shells, ``--org`` is required.

The setup leaves the rest of OpenCode's config alone:

- The ``lightning`` provider is added to your global config, keeping its comments
and other settings. The file is backed up as ``opencode.json.lightning-backup``
first. `code/opencode.json <code/opencode.json>`_ is what a new config looks like.
- The API key goes to OpenCode's credential store, ``auth.json``, next to the keys
``opencode auth login`` saves, never into the config file. Its metadata records
the organization and key, as in `code/opencode-auth.json <code/opencode-auth.json>`_.
- ``lightning/deepseek-v4.1-flash`` becomes the default model only if you have no default yet.
Pass ``--model`` to set one anyway.
- The models, with their names, context windows, output limits and image support,
come from ``https://code.lightning.ai/v1/models``, so new models appear without
a CLI update. If it can't be reached, a built-in list is used.

Preview the changes first, or pick a different default model:

.. code-block:: console

$ lightning code setup opencode --org my-org --dry-run
$ lightning code setup opencode --org my-org --model glm-5.3

Run it again to switch organizations, which creates a key there and revokes the
old one, or to pick up new models. ``--rotate-key`` replaces the key in place.

Check and undo the setup
------------------------

.. code-block:: console

$ lightning code status
OpenCode
Org: my-org
API key: opencode on my-laptop 2026-10-09 (01jexamplekey0000000000000)
Config: ~/.config/opencode/opencode.json
Default: lightning/deepseek-v4.1-flash

$ lightning code remove opencode

``remove`` takes out the provider, a default model on it, and the key,
which it also revokes. Pass ``--keep-key`` to leave the key active.

Use other tools
---------------

``lightning code token`` creates a key for anything else that speaks the OpenAI
or Anthropic API. The key is printed once, so store it straight away.

.. code-block:: console

$ export OPENAI_BASE_URL=https://code.lightning.ai/v1
$ export OPENAI_API_KEY=$(lightning code token --org my-org)

$ export ANTHROPIC_BASE_URL=https://code.lightning.ai
$ export ANTHROPIC_AUTH_TOKEN=$(lightning code token --org my-org --name claude-code)
$ claude --model deepseek-v4.1-flash

$ lightning code token --org my-org --json

Keys created this way are listed and deleted with ``lightning api-key``.
16 changes: 16 additions & 0 deletions python/lightning_sdk/cli/code/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
"""code.lightning.ai CLI commands."""

import rich_click as click


def register_commands(group: click.Group) -> None:
"""Register code.lightning.ai commands with the given group."""
from lightning_sdk.cli.code.remove import remove
from lightning_sdk.cli.code.setup import setup
from lightning_sdk.cli.code.status import status
from lightning_sdk.cli.code.token import token

group.add_command(setup)
group.add_command(status)
group.add_command(remove)
group.add_command(token)
Loading
Loading