---
title: Code
description: >-
  Set up OpenCode, pi, Codex, DeepSeek Harness or Cursor to use
  code.lightning.ai with the lightning code commands, billed to one of your
  organizations.
canonical: 'https://lightning.ai/docs/platform/build/code'
---
# Code {#code}

> **Closed beta:** `lightning code` is in closed beta, and we're rolling it out
> to more people. If you'd like to take part, contact
> [support@lightning.ai](mailto:support@lightning.ai).

[code.lightning.ai](https://code.lightning.ai) serves models for 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, or create an API key
for any other tool. Requests bill the organization you choose, which needs a
Pro, Teams or Enterprise plan.

The commands set up these tools:

| Tool             | Name for the commands |
| ---------------- | --------------------- |
| OpenCode         | `opencode`            |
| pi               | `pi`                  |
| Codex            | `codex`               |
| DeepSeek Harness | `dsh`                 |
| Cursor           | `cursor`              |

The same steps, with your organization filled in, are under **Settings** >
**Lightning Code**, in a plan's **Coding tools** section.

## Before you begin {#before-you-begin}

- The Lightning CLI, signed in. Install or update it with
  `pip install -U lightning-sdk` and run `lightning login`; see
  [CLI](/docs/platform/developers/cli.md). Where `pip` is missing or refuses to
  install outside a virtual environment, as on recent Ubuntu releases, use
  `uv tool install -U lightning-sdk` instead. Sign-in for a machine without a
  browser, such as CI, is not available yet.
- An organization on a Pro, Teams or Enterprise plan. Compare plans on the
  [pricing page](https://lightning.ai/pricing).
- The coding tool installed. Each tool's section below shows how. pi and
  DeepSeek Harness need Node.js 22.19 or newer.

## Set up a tool {#set-up-a-tool}

This adds Lightning as a model provider in the tool and creates an API key that
bills your organization.

1. Run the setup with the tool's name, replacing `my-org` with your
   organization's name:

   ```bash
   lightning code setup opencode --org my-org
   ```

   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 output names the files it changed:

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

2. Start the tool. Its section below says how.

For every tool, the setup:

- Adds a provider called `lightning` and leaves the rest of the tool's config
  as it is, comments included. Before changing a config file you already had,
  it backs it up by appending `.lightning-backup` to its filename. Files that
  hold keys aren't copied.
- Saves the API key where the tool keeps its own keys, not in a file you'd
  share or commit.
- Makes DeepSeek V4.1 Flash the default model only if you don't have one yet.
- Takes the model list from `https://code.lightning.ai/v1/models`, so run the
  setup again to pick up new models.

### Setup options {#setup-options}

| Option         | What it does                                                                |
| -------------- | --------------------------------------------------------------------------- |
| `--org`        | Organization that pays, by name.                                            |
| `--model`      | Makes this model the default, for example `glm-5.3`.                        |
| `--dry-run`    | Shows the changes to the config without writing anything or creating a key. |
| `--rotate-key` | Creates a new API key and revokes the old one.                              |
| `--force`      | Replaces a Lightning setup that you added by hand.                          |

To bill a different organization, run the setup again with its name. This
creates a key there and revokes the old one.

## OpenCode {#opencode}

```bash
curl -fsSL https://opencode.ai/install | bash
lightning code setup opencode --org my-org
opencode
```

The provider goes into `~/.config/opencode/opencode.json`, or
`opencode.jsonc` if that's the file you have. The key goes into OpenCode's
`~/.local/share/opencode/auth.json`. If your config lists providers in
`enabled_providers`, the setup adds `lightning` to it. Switch models with
`/models`.

The installer adds `opencode` to your `PATH` in your shell's startup file, so
start it from a new terminal.

## pi {#pi}

```bash
curl -fsSL https://pi.dev/install.sh | sh
lightning code setup pi --org my-org
pi
```

The provider goes into `~/.pi/agent/models.json`, the key into pi's
`auth.json` and the default model into `settings.json`. When
`PI_CODING_AGENT_DIR` is set, all three are in that directory instead. Switch
models with `/model`.

The installer offers to install Node.js if yours is missing or too old. When
it offers to start pi, say no: pi has no models until you run the setup. Start
pi from a new terminal, so it's on your `PATH`.

## Codex {#codex}

```bash
npm install -g @openai/codex
lightning code setup codex --org my-org
codex --profile lightning
```

Codex gets a profile of its own, `~/.codex/lightning.config.toml`, which it
uses on top of your `config.toml` when you start it with `--profile lightning`.
Your usual Codex setup doesn't change. The profile holds the key, so only you
can read it. Pick another model with `-m`, for example
`codex --profile lightning -m lightning-ai/glm-5.3`.

Image input through Codex isn't supported yet. The other tools send images.

## DeepSeek Harness {#deepseek-harness}

DeepSeek Harness needs Node.js 22.19 or newer. npm installs it on an older
Node.js without a warning, but then `dsh` exits without doing anything. Check
with `node --version`. In a Studio, run `nvm install 22` first.

```bash
npm install -g @deepseek-ai/dsh
lightning code setup dsh --org my-org
dsh web
```

The provider and default model go into the `web` and `headless` profiles, in
`~/.dsh/profiles/<profile>/cordis.patch.yml`, next to your other entries. The
key goes into `~/.dsh/.credentials.yaml` as `LIGHTNING_CODE_API_KEY`.

`dsh web` prints a local address with a token, such as
`http://127.0.0.1:3080/?token=...`. Open it in your browser and pick a
Lightning model under **Model** in the message box.

## Cursor {#cursor}

Cursor's settings can't be changed from outside Cursor, so the setup creates a
key and prints the steps to add it in Cursor. You need a paid Cursor plan.

```bash
lightning code setup cursor --org my-org
```

```text
Cursor now uses code.lightning.ai, billed to My Org [my-org].
  API key: cursor on my-laptop 2026-10-09

Finish in Cursor (needs a paid Cursor plan):
  1. Open Cursor Settings (Cmd+Shift+J on macOS, Ctrl+Shift+J elsewhere) and go to Models.
  2. Under API Keys, paste this into OpenAI API Key and press Enter:
       sk-lit-...
  3. Turn on "Use OpenAI API Key".
  4. Turn on "Override OpenAI Base URL" and enter:
       https://code.lightning.ai/v1
  5. At the top of Models, add these model names and make sure they're switched on:
       lightning-ai/glm-5.3
       lightning-ai/glm-5.3-flash
       lightning-ai/deepseek-v4.1-flash
  6. Open a new chat and pick lightning-ai/deepseek-v4.1-flash.
```

The key is shown only this once. While the base URL override is on, Cursor
sends all OpenAI models to Lightning, so its own GPT and Auto models stop
working until you turn it off. Tab completion keeps using Cursor's models, and
the `cursor-agent` CLI can't use Lightning models.

## Check the setup {#check-the-setup}

```bash
lightning code status
```

```text
OpenCode: billed to my-org
  API key: opencode on my-laptop 2026-10-09 (01jexamplekey0000000000000)
  Config:  ~/.config/opencode/opencode.json
  Default: lightning/deepseek-v4.1-flash
pi: not set up
Codex: billed to my-org
  ...
```

Add `--json` for machine-readable output.

## Remove the setup {#remove-the-setup}

```bash
lightning code remove opencode
```

This removes the `lightning` provider, a default model that uses it, and the API
key, which it also revokes. Files the setup created are deleted, and the rest of
your config stays as it is. To leave the key active, add `--keep-key`. For
Cursor, the command revokes the key and prints how to turn the override off.

## Use other tools {#use-other-tools}

For tools that speak the OpenAI API, create a key with `lightning code token`
and point the tool at `https://code.lightning.ai/v1`:

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

The key is printed once, so store it straight away. Name it with `--name`, or add
`--json` to get the key with its ID, organization and base URL.

Requests name the model by its full ID:

| Model               | ID                                 | Context window | Image input |
| ------------------- | ---------------------------------- | -------------- | ----------- |
| GLM-5.3             | `lightning-ai/glm-5.3`             | 1,048,576      | No          |
| GLM-5.3 Flash       | `lightning-ai/glm-5.3-flash`       | 253,952        | Yes         |
| DeepSeek V4.1 Flash | `lightning-ai/deepseek-v4.1-flash` | 253,952        | Yes         |

For the current list, with each model's output limit and supported parameters,
request `https://code.lightning.ai/v1/models`. It doesn't need a key.

Keys from `lightning code` are listed and deleted with `lightning api-key`.

## Troubleshooting {#troubleshooting}

**`... is on the Free plan, which doesn't include code.lightning.ai.`** The
organization needs a Pro, Teams or Enterprise plan. Upgrade it with the link in
the message, or pass another organization to `--org`.

**`Coding tools are turned off for ...`** An organization admin has turned off
coding tools. Ask them to turn them back on, or pass another organization to
`--org`.

**`... already has a Lightning setup that lightning code didn't make`.** You
added one by hand, for example from another guide. Run the setup again with
`--force` to replace it. Config files are backed up first.

**`No such command 'code'`, or `Invalid value for 'TOOL'`.** Your Lightning CLI
is too old. Update it with `pip install -U lightning-sdk`.

## See also {#see-also}

- [CLI](/docs/platform/developers/cli.md)
- [Model APIs](/docs/platform/inference/model-apis.md)
- [OpenCode documentation](https://opencode.ai/docs)

---

**Navigation**

- Parent: [Build](/docs/platform/build.md)
