---
title: Command Code with AI Gateway
description: Connect Command Code to AI Gateway with your own API key and a custom base URL. Configure models, switch between them, and monitor usage and spending.
url: "https://vercel.com/docs/ai-gateway/coding-agents/command-code"
last_updated: 2026-09-13
related:
  - /docs/cli/ai-gateway
  - /docs/ai-gateway/authentication-and-byok
  - /docs/ai-gateway/coding-agents
  - /docs/ai-gateway/observability-and-spend/logs
  - /docs/ai-gateway/observability-and-spend/usage
install_vercel_plugin: npx plugins add vercel/vercel-plugin
search_with_vercel_cli: npx vercel@latest docs search "<query>"
search_kb_with_vercel_cli: npx vercel@latest kb search "<query>"
---

# Command Code with AI Gateway

Use [Command Code](https://commandcode.ai/) with AI Gateway for model access and spend monitoring. Command Code's bring your own key (BYOK) configuration, currently in beta, lets you set a custom provider endpoint and choose models.

Command Code requires manual configuration. The [Vercel CLI setup command](/docs/cli/ai-gateway#setup) does not configure it.

## Configuring Command Code

- ### Install Command Code
  With Node.js 22 or later installed, run:
  ```bash filename="Terminal"
  npm i -g command-code@latest
  command-code --version
  ```
  The second command prints the installed version. See the [Command Code installation instructions](https://commandcode.ai/docs/quickstart) for platform-specific details.

  If you haven't signed in to Command Code, run:
  ```bash filename="Terminal"
  command-code login
  ```
  Complete the sign-in in your browser, then return to the terminal after Command Code confirms the login.

- ### Create an API key
  Create an [AI Gateway API key](/docs/ai-gateway/authentication-and-byok) and export it in the terminal where you run Command Code:
  ```bash filename="Terminal"
  export AI_GATEWAY_API_KEY="your-ai-gateway-api-key"
  ```
  Replace `your-ai-gateway-api-key` with your key.

- ### Configure the provider
  Create `~/.commandcode/providers.json` with the following configuration. If the file exists, add the `vercel` entry to its `provider` object:
  ```json filename="~/.commandcode/providers.json"
  {
    "provider": {
      "vercel": {
        "name": "Vercel AI Gateway",
        "baseURL": "https://ai-gateway.vercel.sh/coding-agent/v1",
        "apiKey": "$AI_GATEWAY_API_KEY",
        "models": {
          "deepseek/deepseek-v4.1-flash": {}
        }
      }
    }
  }
  ```
  The `baseURL` uses the [coding agent endpoint](/docs/ai-gateway/coding-agents#which-base-url-to-use). Command Code uses OpenAI-compatible Chat Completions by default. Add an entry under `models` for each model you want to use, with its AI Gateway model ID.
  > **💡 Note:** Keep `apiKey` as an environment variable reference. Command Code rejects raw
  > secrets in `providers.json`. A key previously saved for this provider through
  > `/connect` takes precedence. Clear that saved key to use the environment
  > variable.

- ### Start Command Code
  Start a session in the same terminal:
  ```bash filename="Terminal"
  command-code
  ```
  Run `/model` and select a model under **Vercel AI Gateway**. Requests for that model route through AI Gateway. Reopen `/model` after editing `providers.json` to load your changes.

  Send a prompt, then check [AI Gateway logs](/docs/ai-gateway/observability-and-spend/logs) to verify the request.

## Next steps

- [Monitor usage and spending](/docs/ai-gateway/observability-and-spend/usage)
- [Explore Command Code's BYOK options](https://commandcode.ai/docs/byok)

## Search the docs from your terminal

Search the Vercel docs and read pages as Markdown with the Vercel CLI. No login required.

```bash
# Find docs pages by keyword
npx vercel@latest docs search "environment variables"
npx vercel@latest docs search "function timeout"

# Print a docs page as Markdown, by path or URL
npx vercel@latest docs inspect <page>
```

## Search guides from your terminal

Search the Knowledge Base and read guides as Markdown with the Vercel CLI. No login required.

```bash
# Find guides by keyword
npx vercel@latest kb search "rewrites and redirects"
npx vercel@latest kb search "AI SDK streaming"

# Show the latest guides
npx vercel@latest kb

# Print a guide as Markdown, by slug or URL
npx vercel@latest kb inspect <guide>
```

---

[View full sitemap](/docs/sitemap)


If you encounter incorrect information, can’t find what you need, need a capability Vercel doesn’t currently offer, or have any other feedback to report, please do it by following the instructions at https://vercel.com/feedback.md.
