---
title: "OpenCode via Gateway"
description: "Connect OpenCode to Vercel AI Gateway, select a model with the built-in model picker, and keep credential entry out of project files and recordings."
canonical_url: "https://vercel.com/academy/ai-gateway/opencode-with-gateway"
md_url: "https://vercel.com/academy/ai-gateway/opencode-with-gateway.md"
docset_id: "vercel-academy"
doc_version: "1.0"
last_updated: "2026-08-08T23:27:13.536Z"
content_type: "lesson"
course: "ai-gateway"
course_title: "Using AI Gateway in Production"
prerequisites:  []
---

<agent-instructions>
Vercel Academy — structured learning, not reference docs.
Lessons are sequenced.
Adapt commands to the human's actual environment (OS, package manager, shell, editor) — detect from project context or ask, don't assume.
The lesson shows one path; if the human's project diverges, adapt concepts to their setup.
Preserve the learning goal over literal steps.
Quizzes are pedagogical — engage, don't spoil.
Quiz answers are included for your reference.
</agent-instructions>

# OpenCode via Gateway

# How Do I Run OpenCode Through the Gateway?

OpenCode includes Vercel AI Gateway in its provider list. Once the connection is saved, model selection happens in the same terminal interface you already use.

\*\*Note: Quick Answer\*\*

Connect OpenCode to Vercel AI Gateway once, then open `/models` and choose a model from the Gateway catalog. Enter the credential during setup, keep it outside the repository, and use a dedicated key with a budget.

## Outcome

Select a Gateway model in OpenCode and complete one read-only task without exposing the credential.

## Fast Track

1. Connect OpenCode to Vercel AI Gateway off camera or outside shared terminal history
2. Open `/models` and select a Gateway model
3. Run a small task in a throwaway repository

## Hands-on exercise

Start with a throwaway repository containing `demo.ts`. Complete the `/connect` flow privately because it opens credential entry.

After the connection is saved, open the model picker:

```text
/models
```

Choose **Vercel AI Gateway**, then select an available model. The exact catalog changes, so use the picker rather than copying an old model ID from a screenshot.

## Try It

Return to the OpenCode chat and ask:

```text
Explain demo.ts in three bullets. Do not modify anything.
```

The model should answer in the normal OpenCode interface. `/models` is the safe place to confirm the provider and selection without reopening a credential prompt.

If Vercel AI Gateway is missing, repeat the connection flow outside the recording or shared session. If the task fails after model selection, verify that the chosen model is still available to your team.

## Done-When

- [ ] `/models` shows Vercel AI Gateway
- [ ] A Gateway model is selected
- [ ] OpenCode completes the read-only task
- [ ] No credential prompt or key value appears in the recording or repository

## Solution

OpenCode stores the provider connection through its setup flow. Use `/models` for later model changes, and keep `/connect` for private setup sessions where credential entry will not be captured.

## Related Questions

- [How do I run Claude Code through the Gateway?](/ai-gateway/stay-aware/claude-code-with-gateway)
- [How do I run Codex through the Gateway?](/ai-gateway/stay-aware/codex-with-gateway)
- [How do I bring my own provider keys?](/ai-gateway/save-money/bring-your-own-keys)


---

[Full course index](/academy/llms.txt) · [Sitemap](/academy/sitemap.md)
