llm-providers.md

  1---
  2title: LLM Providers - Use Your Own API Keys in Zed
  3description: Bring your own API keys to Zed. Set up Anthropic, OpenAI, Google AI, Ollama, DeepSeek, Mistral, OpenRouter, Vercel AI Gateway, and more.
  4---
  5
  6# LLM Providers
  7
  8To use AI in Zed, you need to have at least one large language model provider set up. Once configured, providers are available in the [Agent Panel](./agent-panel.md) and [Inline Assistant](./inline-assistant.md).
  9
 10You can do that by either subscribing to [one of Zed's plans](./plans-and-usage.md), or by using API keys you already have for the supported providers. For general AI setup, see [Configuration](./configuration.md).
 11
 12## Use Your Own Keys {#use-your-own-keys}
 13
 14If you already have an API key for a provider like Anthropic or OpenAI, you can add it to Zed. No Zed subscription required.
 15
 16To add an existing API key to a given provider, go to the Agent Panel settings (`agent: open settings`), look for the desired provider, paste the key into the input, and hit enter.
 17
 18> Note: API keys are _not_ stored as plain text in your settings file, but rather in your OS's secure credential storage.
 19
 20## Supported Providers
 21
 22Zed supports these providers with your own API keys:
 23
 24- [Amazon Bedrock](#amazon-bedrock)
 25- [Anthropic](#anthropic)
 26- [DeepSeek](#deepseek)
 27- [GitHub Copilot Chat](#github-copilot-chat)
 28- [Google AI](#google-ai)
 29- [LM Studio](#lmstudio)
 30- [Mistral](#mistral)
 31- [Ollama](#ollama)
 32- [OpenAI](#openai)
 33- [OpenAI API Compatible](#openai-api-compatible)
 34- [OpenCode](#opencode)
 35- [OpenRouter](#openrouter)
 36- [Vercel AI Gateway](#vercel-ai-gateway)
 37- [Vercel](#vercel-v0)
 38- [xAI](#xai)
 39
 40### Amazon Bedrock {#amazon-bedrock}
 41
 42> Supports tool use with models that support streaming tool use.
 43> More details can be found in the [Amazon Bedrock's Tool Use documentation](https://docs.aws.amazon.com/bedrock/latest/userguide/conversation-inference-supported-models-features.html).
 44
 45To use Amazon Bedrock's models, an AWS authentication is required.
 46Ensure your credentials have the following permissions set up:
 47
 48- `bedrock:InvokeModelWithResponseStream`
 49- `bedrock:InvokeModel`
 50
 51Your IAM policy should look similar to:
 52
 53```json
 54{
 55  "Version": "2012-10-17",
 56  "Statement": [
 57    {
 58      "Effect": "Allow",
 59      "Action": [
 60        "bedrock:InvokeModel",
 61        "bedrock:InvokeModelWithResponseStream"
 62      ],
 63      "Resource": "*"
 64    }
 65  ]
 66}
 67```
 68
 69With that done, choose one of the three authentication methods:
 70
 71#### Authentication via Named Profile (Recommended)
 72
 731. Ensure you have the AWS CLI installed and configured with a named profile
 742. Open your settings file (`zed: open settings file`) and include the `bedrock` key under `language_models` with the following settings:
 75   ```json [settings]
 76   {
 77     "language_models": {
 78       "bedrock": {
 79         "authentication_method": "named_profile",
 80         "region": "your-aws-region",
 81         "profile": "your-profile-name"
 82       }
 83     }
 84   }
 85   ```
 86
 87#### Authentication via Static Credentials
 88
 89While it's possible to configure through the Agent Panel settings UI by entering your AWS access key and secret directly, we recommend using named profiles instead for better security practices.
 90To do this:
 91
 921. Create an IAM User in the [IAM Console](https://us-east-1.console.aws.amazon.com/iam/home?region=us-east-1#/users).
 932. Create security credentials for that User, save them and keep them secure.
 943. Open the Agent Configuration with (`agent: open settings`) and go to the Amazon Bedrock section
 954. Copy the credentials from Step 2 into the respective **Access Key ID**, **Secret Access Key**, and **Region** fields.
 96
 97#### Authentication via Bedrock API Key
 98
 99Amazon Bedrock also supports [API Keys](https://docs.aws.amazon.com/bedrock/latest/userguide/api-keys-use.html), which authenticate directly without requiring IAM users or named profiles.
100
1011. Create an API Key in the [Amazon Bedrock Console](https://console.aws.amazon.com/bedrock/)
1022. Open the Agent Configuration with (`agent: open settings`) and go to the Amazon Bedrock section
1033. Enter your Bedrock API key in the **API Key** field and select your **Region**
104
105```json [settings]
106{
107  "language_models": {
108    "bedrock": {
109      "authentication_method": "api_key",
110      "region": "your-aws-region"
111    }
112  }
113}
114```
115
116The API key itself is stored securely in your OS keychain, not in your settings file.
117
118#### Cross-Region Inference
119
120The Zed implementation of Amazon Bedrock uses [Cross-Region inference](https://docs.aws.amazon.com/bedrock/latest/userguide/cross-region-inference.html) to improve availability and throughput.
121With Cross-Region inference, you can distribute traffic across multiple AWS Regions, enabling higher throughput.
122
123##### Regional vs Global Inference Profiles
124
125Bedrock supports two types of cross-region inference profiles:
126
127- **Regional profiles** (default): Route requests within a specific geography (US, EU, APAC). For example, `us-east-1` uses the `us.*` profile which routes across `us-east-1`, `us-east-2`, and `us-west-2`.
128- **Global profiles**: Route requests across all commercial AWS Regions for maximum availability and performance.
129
130By default, Zed uses **regional profiles** which keep your data within the same geography. You can opt into global profiles by adding `"allow_global": true` to your Bedrock configuration:
131
132```json [settings]
133{
134  "language_models": {
135    "bedrock": {
136      "authentication_method": "named_profile",
137      "region": "your-aws-region",
138      "profile": "your-profile-name",
139      "allow_global": true
140    }
141  }
142}
143```
144
145**Note:** Only select newer models support global inference profiles. See the [AWS Bedrock supported models documentation](https://docs.aws.amazon.com/bedrock/latest/userguide/inference-profiles-support.html#inference-profiles-support-system) for the current list of models that support global inference. If you encounter availability issues with a model in your region, enabling `allow_global` may resolve them.
146
147Although the data remains stored only in the source Region, your input prompts and output results might move outside of your source Region during cross-Region inference.
148All data will be transmitted encrypted across Amazon's secure network.
149
150We will support Cross-Region inference for each of the models on a best-effort basis, please refer to the [Cross-Region Inference method Code](https://github.com/zed-industries/zed/blob/main/crates/bedrock/src/models.rs#L297).
151
152For the most up-to-date supported regions and models, refer to the [Supported Models and Regions for Cross Region inference](https://docs.aws.amazon.com/bedrock/latest/userguide/inference-profiles-support.html).
153
154#### Extended Context Window {#bedrock-extended-context}
155
156Anthropic models on Bedrock support a 1M token extended context window through the `anthropic_beta` API parameter. To enable this feature, set `"allow_extended_context": true` in your Bedrock configuration:
157
158```json [settings]
159{
160  "language_models": {
161    "bedrock": {
162      "authentication_method": "named_profile",
163      "region": "your-aws-region",
164      "profile": "your-profile-name",
165      "allow_extended_context": true
166    }
167  }
168}
169```
170
171Zed enables extended context for supported models (Claude Sonnet 4.5, Claude Opus 4.6, and Claude Opus 4.7). Extended context usage may increase API costs—refer to AWS Bedrock pricing for details.
172
173#### Image Support {#bedrock-image-support}
174
175Bedrock models that support vision (Claude 3 and later, Amazon Nova Pro and Lite, Meta Llama 3.2 Vision models, Mistral Pixtral) can receive images in conversations and tool results.
176
177### Anthropic {#anthropic}
178
179You can use Anthropic models by choosing them via the model dropdown in the Agent Panel.
180
1811. Sign up for Anthropic and [create an API key](https://console.anthropic.com/settings/keys)
1822. Make sure that your Anthropic account has credits
1833. Open the settings view (`agent: open settings`) and go to the Anthropic section
1844. Enter your Anthropic API key
185
186Even if you pay for Claude Pro, you will still have to [pay for additional credits](https://console.anthropic.com/settings/plans) to use it via the API.
187
188Zed will also use the `ANTHROPIC_API_KEY` environment variable if it's defined.
189
190#### Custom Models {#anthropic-custom-models}
191
192You can add custom models to the Anthropic provider by adding the following to your Zed settings file ([how to edit](../configuring-zed.md#settings-files)):
193
194```json [settings]
195{
196  "language_models": {
197    "anthropic": {
198      "available_models": [
199        {
200          "name": "claude-3-5-sonnet-20240620",
201          "display_name": "Sonnet 2024-June",
202          "max_tokens": 128000,
203          "max_output_tokens": 2560,
204          "cache_configuration": {
205            "max_cache_anchors": 10,
206            "min_total_token": 10000,
207            "should_speculate": false
208          },
209          "tool_override": "some-model-that-supports-toolcalling"
210        }
211      ]
212    }
213  }
214}
215```
216
217Custom models will be listed in the model dropdown in the Agent Panel.
218
219You can configure a model to use [extended thinking](https://docs.anthropic.com/en/docs/about-claude/models/extended-thinking-models) (if it supports it) by changing the mode in your model's configuration to `thinking`, for example:
220
221```json
222{
223  "name": "claude-sonnet-4-latest",
224  "display_name": "claude-sonnet-4-thinking",
225  "max_tokens": 200000,
226  "mode": {
227    "type": "thinking",
228    "budget_tokens": 4096
229  }
230}
231```
232
233### DeepSeek {#deepseek}
234
2351. Visit the DeepSeek platform and [create an API key](https://platform.deepseek.com/api_keys)
2362. Open the settings view (`agent: open settings`) and go to the DeepSeek section
2373. Enter your DeepSeek API key
238
239The DeepSeek API key will be saved in your keychain.
240
241Zed will also use the `DEEPSEEK_API_KEY` environment variable if it's defined.
242
243#### Custom Models {#deepseek-custom-models}
244
245The Zed agent comes pre-configured to use the latest version for common models (DeepSeek Chat, DeepSeek Reasoner).
246If you wish to use alternate models or customize the API endpoint, you can do so by adding the following to your Zed settings file ([how to edit](../configuring-zed.md#settings-files)):
247
248```json [settings]
249{
250  "language_models": {
251    "deepseek": {
252      "api_url": "https://api.deepseek.com",
253      "available_models": [
254        {
255          "name": "deepseek-chat",
256          "display_name": "DeepSeek Chat",
257          "max_tokens": 64000
258        },
259        {
260          "name": "deepseek-reasoner",
261          "display_name": "DeepSeek Reasoner",
262          "max_tokens": 64000,
263          "max_output_tokens": 4096
264        }
265      ]
266    }
267  }
268}
269```
270
271Custom models will be listed in the model dropdown in the Agent Panel.
272You can also modify the `api_url` to use a custom endpoint if needed.
273
274### GitHub Copilot Chat {#github-copilot-chat}
275
276You can use GitHub Copilot Chat with the Zed agent by choosing it via the model dropdown in the Agent Panel.
277
2781. Open the settings view (`agent: open settings`) and go to the GitHub Copilot Chat section
2792. Click on `Sign in to use GitHub Copilot`, follow the steps shown in the modal.
280
281Alternatively, you can provide an OAuth token via the `GH_COPILOT_TOKEN` environment variable.
282
283> **Note**: If you don't see specific models in the dropdown, you may need to enable them in your [GitHub Copilot settings](https://github.com/settings/copilot/features).
284
285To use Copilot Enterprise with Zed (for both agent and completions), you must configure your enterprise endpoint as described in [Configuring GitHub Copilot Enterprise](./edit-prediction.md#github-copilot-enterprise).
286
287### Google AI {#google-ai}
288
289You can use Gemini models with the Zed agent by choosing it via the model dropdown in the Agent Panel.
290
2911. Go to the Google AI Studio site and [create an API key](https://aistudio.google.com/app/apikey).
2922. Open the settings view (`agent: open settings`) and go to the Google AI section
2933. Enter your Google AI API key and press enter.
294
295The Google AI API key will be saved in your keychain.
296
297Zed will also use the `GEMINI_API_KEY` environment variable if it's defined. See [Using Gemini API keys](https://ai.google.dev/gemini-api/docs/api-key) in the Gemini docs for more.
298
299#### Custom Models {#google-ai-custom-models}
300
301By default, Zed will use `stable` versions of models, but you can use specific versions of models, including [experimental models](https://ai.google.dev/gemini-api/docs/models/experimental-models). You can configure a model to use [thinking mode](https://ai.google.dev/gemini-api/docs/thinking) (if it supports it) by adding a `mode` configuration to your model. This is useful for controlling reasoning token usage and response speed. If not specified, Gemini will automatically choose the thinking budget.
302
303Here is an example of a custom Google AI model you could add to your Zed settings file ([how to edit](../configuring-zed.md#settings-files)):
304
305```json [settings]
306{
307  "language_models": {
308    "google": {
309      "available_models": [
310        {
311          "name": "gemini-3.1-pro-preview",
312          "display_name": "Gemini 3.1 Pro",
313          "max_tokens": 1000000,
314          "mode": {
315            "type": "thinking",
316            "budget_tokens": 24000
317          }
318        },
319        {
320          "name": "gemini-3-flash-preview",
321          "display_name": "Gemini 3 Flash (Thinking)",
322          "max_tokens": 1000000,
323          "mode": {
324            "type": "thinking",
325            "budget_tokens": 24000
326          }
327        }
328      ]
329    }
330  }
331}
332```
333
334Custom models will be listed in the model dropdown in the Agent Panel.
335
336### LM Studio {#lmstudio}
337
3381. Download and install [the latest version of LM Studio](https://lmstudio.ai/download)
3392. In the app press `cmd/ctrl-shift-m` and download at least one model (e.g., qwen2.5-coder-7b). Alternatively, you can get models via the LM Studio CLI:
340
341   ```sh
342   lms get qwen2.5-coder-7b
343   ```
344
3453. Make sure the LM Studio API server is running by executing:
346
347   ```sh
348   lms server start
349   ```
350
351Tip: Set [LM Studio as a login item](https://lmstudio.ai/docs/advanced/headless#run-the-llm-service-on-machine-login) to automate running the LM Studio server.
352
353### Mistral {#mistral}
354
3551. Visit the Mistral platform and [create an API key](https://console.mistral.ai/api-keys/)
3562. Open the configuration view (`agent: open settings`) and navigate to the Mistral section
3573. Enter your Mistral API key
358
359The Mistral API key will be saved in your keychain.
360
361Zed will also use the `MISTRAL_API_KEY` environment variable if it's defined.
362
363#### Custom Models {#mistral-custom-models}
364
365The Zed agent comes pre-configured with several Mistral models (codestral-latest, mistral-large-latest, mistral-medium-latest, mistral-small-latest, open-mistral-nemo, and open-codestral-mamba).
366All the default models support tool use.
367If you wish to use alternate models or customize their parameters, you can do so by adding the following to your Zed settings file ([how to edit](../configuring-zed.md#settings-files)):
368
369```json [settings]
370{
371  "language_models": {
372    "mistral": {
373      "api_url": "https://api.mistral.ai/v1",
374      "available_models": [
375        {
376          "name": "mistral-tiny-latest",
377          "display_name": "Mistral Tiny",
378          "max_tokens": 32000,
379          "max_output_tokens": 4096,
380          "max_completion_tokens": 1024,
381          "supports_tools": true,
382          "supports_images": false
383        }
384      ]
385    }
386  }
387}
388```
389
390Custom models will be listed in the model dropdown in the Agent Panel.
391
392### Ollama {#ollama}
393
394Download and install Ollama from [ollama.com/download](https://ollama.com/download) (Linux or macOS) and ensure it's running with `ollama --version`.
395
3961. Download one of the [available models](https://ollama.com/models), for example, for `mistral`:
397
398   ```sh
399   ollama pull mistral
400   ```
401
4022. Make sure that the Ollama server is running. You can start it either via running Ollama.app (macOS) or launching:
403
404   ```sh
405   ollama serve
406   ```
407
4083. In the Agent Panel, select one of the Ollama models using the model dropdown.
409
410#### Ollama Autodiscovery
411
412Zed will automatically discover models that Ollama has pulled. You can turn this off by setting
413the `auto_discover` field in the Ollama settings. If you do this, you should manually specify which
414models are available.
415
416```json [settings]
417{
418  "language_models": {
419    "ollama": {
420      "api_url": "http://localhost:11434",
421      "auto_discover": false,
422      "available_models": [
423        {
424          "name": "qwen2.5-coder",
425          "display_name": "qwen 2.5 coder",
426          "max_tokens": 32768,
427          "supports_tools": true,
428          "supports_thinking": true,
429          "supports_images": true
430        }
431      ]
432    }
433  }
434}
435```
436
437#### Ollama Context Length {#ollama-context}
438
439Zed API requests to Ollama include the context length as the `num_ctx` parameter. By default, Zed uses a context length of `4096` tokens for all Ollama models.
440
441> **Note**: Token counts displayed in the Agent Panel are only estimates and will differ from the model's native tokenizer.
442
443You can set a context length for all Ollama models using the `context_window` setting. This can also be configured in the Ollama provider settings UI:
444
445```json [settings]
446{
447  "language_models": {
448    "ollama": {
449      "context_window": 8192
450    }
451  }
452}
453```
454
455Alternatively, you can configure the context length per-model using the `max_tokens` field in `available_models`:
456
457```json [settings]
458{
459  "language_models": {
460    "ollama": {
461      "api_url": "http://localhost:11434",
462      "available_models": [
463        {
464          "name": "qwen2.5-coder",
465          "display_name": "qwen 2.5 coder 32K",
466          "max_tokens": 32768,
467          "supports_tools": true,
468          "supports_thinking": true,
469          "supports_images": true
470        }
471      ]
472    }
473  }
474}
475```
476
477> **Note**: If `context_window` is set, it overrides any per-model `max_tokens` values.
478
479If you specify a context length that is too large for your hardware, Ollama will log an error.
480You can watch these logs by running: `tail -f ~/.ollama/logs/ollama.log` (macOS) or `journalctl -u ollama -f` (Linux).
481Depending on the memory available on your machine, you may need to adjust the context length to a smaller value.
482
483You may also optionally specify a value for `keep_alive` for each available model.
484This can be an integer (seconds) or alternatively a string duration like "5m", "10m", "1h", "1d", etc.
485For example, `"keep_alive": "120s"` will allow the remote server to unload the model (freeing up GPU VRAM) after 120 seconds.
486
487The `supports_tools` option controls whether the model will use additional tools.
488If the model is tagged with `tools` in the Ollama catalog, this option should be supplied, and the built-in profiles `Ask` and `Write` can be used.
489If the model is not tagged with `tools` in the Ollama catalog, this option can still be supplied with the value `true`; however, be aware that only the `Minimal` built-in profile will work.
490
491The `supports_thinking` option controls whether the model will perform an explicit "thinking" (reasoning) pass before producing its final answer.
492If the model is tagged with `thinking` in the Ollama catalog, set this option and you can use it in Zed.
493
494The `supports_images` option enables the model's vision capabilities, allowing it to process images included in the conversation context.
495If the model is tagged with `vision` in the Ollama catalog, set this option and you can use it in Zed.
496
497#### Ollama Authentication
498
499In addition to running Ollama on your own hardware, which generally does not require authentication, Zed also supports connecting to remote Ollama instances. API keys are required for authentication.
500
501One such service is [Ollama Turbo](https://ollama.com/turbo). To configure Zed to use Ollama Turbo:
502
5031. Sign in to your Ollama account and subscribe to Ollama Turbo
5042. Visit [ollama.com/settings/keys](https://ollama.com/settings/keys) and create an API key
5053. Open the settings view (`agent: open settings`) and go to the Ollama section
5064. Paste your API key and press enter.
5075. For the API URL enter `https://ollama.com`
508
509Zed will also use the `OLLAMA_API_KEY` environment variables if defined.
510
511### OpenAI {#openai}
512
5131. Visit the OpenAI platform and [create an API key](https://platform.openai.com/account/api-keys)
5142. Make sure that your OpenAI account has credits
5153. Open the settings view (`agent: open settings`) and go to the OpenAI section
5164. Enter your OpenAI API key
517
518The OpenAI API key will be saved in your keychain.
519
520Zed will also use the `OPENAI_API_KEY` environment variable if it's defined.
521
522#### Custom Models {#openai-custom-models}
523
524The Zed agent comes pre-configured to use the latest version for common OpenAI models (GPT-5.2, GPT-5 mini, GPT-5.2 Codex, and others).
525To use alternate models, perhaps a preview release, or if you wish to control the request parameters, you can do so by adding the following to your Zed settings file ([how to edit](../configuring-zed.md#settings-files)):
526
527```json [settings]
528{
529  "language_models": {
530    "openai": {
531      "available_models": [
532        {
533          "name": "gpt-5.2",
534          "display_name": "gpt-5.2 high",
535          "reasoning_effort": "high",
536          "max_tokens": 272000,
537          "max_completion_tokens": 20000
538        },
539        {
540          "name": "gpt-5-nano",
541          "display_name": "GPT-5 Nano",
542          "max_tokens": 400000
543        },
544        {
545          "name": "gpt-5.2-codex",
546          "display_name": "GPT-5.2 Codex",
547          "max_tokens": 128000,
548          "capabilities": {
549            "chat_completions": false
550          }
551        }
552      ]
553    }
554  }
555}
556```
557
558You must provide the model's context window in the `max_tokens` parameter; this can be found in the [OpenAI model documentation](https://platform.openai.com/docs/models).
559
560For reasoning-focused models, set `max_completion_tokens` as well to avoid incurring high reasoning token costs.
561
562If a model does not support the `/chat/completions` endpoint (for example `gpt-5.2-codex`), disable it by setting `capabilities.chat_completions` to `false`. Zed will use the Responses endpoint instead.
563
564Custom models will be listed in the model dropdown in the Agent Panel.
565
566### OpenAI API Compatible {#openai-api-compatible}
567
568Zed supports using [OpenAI compatible APIs](https://platform.openai.com/docs/api-reference/chat) by specifying a custom `api_url` and `available_models` for the OpenAI provider.
569This is useful for connecting to other hosted services (like Together AI, Anyscale, etc.) or local models.
570
571You can add a custom, OpenAI-compatible model either via the UI or by editing your settings file.
572
573To do it via the UI, go to the Agent Panel settings (`agent: open settings`) and look for the "Add Provider" button to the right of the "LLM Providers" section title.
574Then, fill up the input fields available in the modal.
575
576To do it via your settings file ([how to edit](../configuring-zed.md#settings-files)), add the following snippet under `language_models`:
577
578```json [settings]
579{
580  "language_models": {
581    "openai_compatible": {
582      // Using Together AI as an example
583      "Together AI": {
584        "api_url": "https://api.together.xyz/v1",
585        "available_models": [
586          {
587            "name": "mistralai/Mixtral-8x7B-Instruct-v0.1",
588            "display_name": "Together Mixtral 8x7B",
589            "max_tokens": 32768,
590            "capabilities": {
591              "tools": true,
592              "images": false,
593              "parallel_tool_calls": false,
594              "prompt_cache_key": false
595            }
596          }
597        ]
598      }
599    }
600  }
601}
602```
603
604By default, OpenAI-compatible models inherit the following capabilities:
605
606- `tools`: true (supports tool/function calling)
607- `images`: false (does not support image inputs)
608- `parallel_tool_calls`: false (does not support `parallel_tool_calls` parameter)
609- `prompt_cache_key`: false (does not support `prompt_cache_key` parameter)
610- `chat_completions`: true (calls the `/chat/completions` endpoint)
611- `interleaved_reasoning`: false (thinking tokens are sent inline in message text; set to true to send them as a dedicated `reasoning_content` field for models that expect it)
612
613If a provider exposes models that only work with the Responses API, set `chat_completions` to `false` for those entries. Zed uses the Responses endpoint for these models.
614
615Note that LLM API keys aren't stored in your settings file.
616So, ensure you have it set in your environment variables (`<PROVIDER_NAME>_API_KEY=<your api key>`) so your settings can pick it up. In the example above, it would be `TOGETHER_AI_API_KEY=<your api key>`.
617
618### OpenCode {#opencode}
619
620OpenCode offers multiple ways to access AI models:
621
622- [OpenCode Zen](https://opencode.ai/zen/): a pay-as-you-go subscription with access to a large number of tested and verified models
623- [OpenCode Zen Free](https://opencode.ai/docs/zen/#pricing): free access to a limited set of models, with data and feedback collected to improve the models
624- [OpenCode Go](https://opencode.ai/go): a low-cost monthly subscription with access to a validated set of open coding models
625
6261. Visit [OpenCode Console](https://opencode.ai/auth) and create an account
6272. Free models are available without payment. To use Zen or Go models, make sure you have enough credits or an active subscription
6283. Generate an API key from the "API Keys" section in the OpenCode Console
6294. Open the settings view (`agent: open settings`) and go to the OpenCode section
6305. Enter your OpenCode API key
631
632The OpenCode API key will be saved in your keychain.
633
634Zed will also use the `OPENCODE_API_KEY` environment variable if it's defined.
635
636By default, models from all subscription types are shown. Optionally, you can hide subscriptions that are not relevant to you by clicking the toggles or by adding the following to your settings:
637
638```json [settings]
639{
640  "language_models": {
641    "opencode": {
642      "show_zen_models": true,
643      "show_go_models": false,
644      "show_free_models": false
645    }
646  }
647}
648```
649
650#### Custom Models {#opencode-custom-models}
651
652The Zed agent comes pre-configured with OpenCode models. If you wish to use newer models or models with custom endpoints, you can do so by adding the following to your Zed settings file ([how to edit](../configuring-zed.md#settings-files)):
653
654```json [settings]
655{
656  "language_models": {
657    "opencode": {
658      "available_models": [
659        {
660          "name": "my-custom-model",
661          "display_name": "My Custom Model",
662          "max_tokens": 123456,
663          "max_output_tokens": 98765,
664          "protocol": "openai_chat",
665          "subscription": "go",
666          "custom_model_api_url": "https://example.com/zen"
667        }
668      ]
669    }
670  }
671}
672```
673
674The available configuration options for custom models are:
675
676- `name` (required): model id used by OpenCode, for example `glm-9000`
677- `display_name` (optional): human-readable model name shown in the UI, for example `Custom GLM 9000`
678- `max_tokens` (required): maximum model context window size, for example `1000000`
679- `max_output_tokens` (optional): maximum tokens the model can generate, for example `64000`
680- `protocol` (required): model API protocol, one of `"anthropic"`, `"openai_responses"`, `"openai_chat"`, or `"google"`
681- `subscription` (optional): `"zen"`, `"go"`, or `"free"` (defaults to `"zen"`)
682- `custom_model_api_url` (optional): custom API base URL to use instead of the default OpenCode API
683
684Custom models will be listed in the model dropdown in the Agent Panel.
685
686### OpenRouter {#openrouter}
687
688OpenRouter provides access to multiple AI models through a single API. It supports tool use for compatible models.
689
6901. Visit [OpenRouter](https://openrouter.ai) and create an account
6912. Generate an API key from your [OpenRouter keys page](https://openrouter.ai/keys)
6923. Open the settings view (`agent: open settings`) and go to the OpenRouter section
6934. Enter your OpenRouter API key
694
695The OpenRouter API key will be saved in your keychain.
696
697Zed will also use the `OPENROUTER_API_KEY` environment variable if it's defined.
698
699When using OpenRouter as your assistant provider, you must explicitly select a model in your settings. OpenRouter no longer provides a default model selection.
700
701Configure your preferred OpenRouter model in `settings.json`:
702
703```json [settings]
704{
705  "agent": {
706    "default_model": {
707      "provider": "openrouter",
708      "model": "openrouter/auto"
709    }
710  }
711}
712```
713
714The `openrouter/auto` model automatically routes your requests to the most appropriate available model. You can also specify any model available through OpenRouter's API.
715
716#### Custom Models {#openrouter-custom-models}
717
718You can add custom models to the OpenRouter provider by adding the following to your Zed settings file ([how to edit](../configuring-zed.md#settings-files)):
719
720```json [settings]
721{
722  "language_models": {
723    "open_router": {
724      "api_url": "https://openrouter.ai/api/v1",
725      "available_models": [
726        {
727          "name": "google/gemini-2.0-flash-thinking-exp",
728          "display_name": "Gemini 2.0 Flash (Thinking)",
729          "max_tokens": 200000,
730          "max_output_tokens": 8192,
731          "supports_tools": true,
732          "supports_images": true,
733          "mode": {
734            "type": "thinking",
735            "budget_tokens": 8000
736          }
737        }
738      ]
739    }
740  }
741}
742```
743
744The available configuration options for each model are:
745
746- `name` (required): The model identifier used by OpenRouter
747- `display_name` (optional): A human-readable name shown in the UI
748- `max_tokens` (required): The model's context window size
749- `max_output_tokens` (optional): Maximum tokens the model can generate
750- `max_completion_tokens` (optional): Maximum completion tokens
751- `supports_tools` (optional): Whether the model supports tool/function calling
752- `supports_images` (optional): Whether the model supports image inputs
753- `mode` (optional): Special mode configuration for thinking models
754
755You can find available models and their specifications on the [OpenRouter models page](https://openrouter.ai/models).
756
757Custom models will be listed in the model dropdown in the Agent Panel.
758
759#### Provider Routing
760
761You can optionally control how OpenRouter routes a given custom model request among underlying upstream providers via the `provider` object on each model entry.
762
763Supported fields (all optional):
764
765- `order`: Array of provider slugs to try first, in order (e.g. `["anthropic", "openai"]`)
766- `allow_fallbacks` (default: `true`): Whether fallback providers may be used if preferred ones are unavailable
767- `require_parameters` (default: `false`): Only use providers that support every parameter you supplied
768- `data_collection` (default: `allow`): `"allow"` or `"disallow"` (controls use of providers that may store data)
769- `only`: Whitelist of provider slugs allowed for this request
770- `ignore`: Provider slugs to skip
771- `quantizations`: Restrict to specific quantization variants (e.g. `["int4","int8"]`)
772- `sort`: Sort strategy for candidate providers (e.g. `"price"` or `"throughput"`)
773
774Example adding routing preferences to a model:
775
776```json [settings]
777{
778  "language_models": {
779    "open_router": {
780      "api_url": "https://openrouter.ai/api/v1",
781      "available_models": [
782        {
783          "name": "openrouter/auto",
784          "display_name": "Auto Router (Tools Preferred)",
785          "max_tokens": 2000000,
786          "supports_tools": true,
787          "provider": {
788            "order": ["anthropic", "openai"],
789            "allow_fallbacks": true,
790            "require_parameters": true,
791            "only": ["anthropic", "openai", "google"],
792            "ignore": ["cohere"],
793            "quantizations": ["int8"],
794            "sort": "price",
795            "data_collection": "allow"
796          }
797        }
798      ]
799    }
800  }
801}
802```
803
804These routing controls let you fine‑tune cost, capability, and reliability trade‑offs without changing the model name you select in the UI.
805
806### Vercel AI Gateway {#vercel-ai-gateway}
807
808[Vercel AI Gateway](https://vercel.com/ai-gateway) provides access to many models through a single OpenAI-compatible endpoint.
809
8101. Create an API key from your [Vercel AI Gateway keys page](https://vercel.com/d?to=%2F%5Bteam%5D%2F%7E%2Fai%2Fapi-keys&title=Go+to+AI+Gateway)
8112. Open the settings view (`agent: open settings`) and go to the **Vercel AI Gateway** section
8123. Enter your Vercel AI Gateway API key
813
814The Vercel AI Gateway API key will be saved in your keychain.
815
816Zed will also use the `VERCEL_AI_GATEWAY_API_KEY` environment variable if it's defined.
817
818You can also set a custom endpoint for Vercel AI Gateway in your settings file:
819
820```json [settings]
821{
822  "language_models": {
823    "vercel_ai_gateway": {
824      "api_url": "https://ai-gateway.vercel.sh/v1"
825    }
826  }
827}
828```
829
830### Vercel v0 {#vercel-v0}
831
832[Vercel v0](https://v0.app/docs/api/model) is a model for generating full-stack apps, with framework-aware completions for stacks like Next.js and Vercel.
833It supports text and image inputs and provides fast streaming responses.
834
835The v0 models are [OpenAI-compatible models](#openai-api-compatible), and Vercel appears as a dedicated provider in the panel's settings view.
836
837To start using it with Zed, ensure you have first created a [v0 API key](https://v0.dev/chat/settings/keys).
838Once you have it, paste it directly into the Vercel provider section in the panel's settings view.
839
840You should then find it as `v0-1.5-md` in the model dropdown in the Agent Panel.
841
842### xAI {#xai}
843
844Zed includes a dedicated [xAI](https://x.ai/) provider. You can use your own API key to access Grok models.
845
8461. [Create an API key in the xAI Console](https://console.x.ai/team/default/api-keys)
8472. Open the settings view (`agent: open settings`) and go to the **xAI** section
8483. Enter your xAI API key
849
850The xAI API key will be saved in your keychain. Zed will also use the `XAI_API_KEY` environment variable if it's defined.
851
852> **Note:** The xAI API is OpenAI-compatible, and Zed also includes a dedicated xAI provider. We recommend using the dedicated `x_ai` provider configuration instead of the [OpenAI API Compatible](#openai-api-compatible) method.
853
854#### Custom Models {#xai-custom-models}
855
856The Zed agent comes pre-configured with common Grok models. If you wish to use alternate models or customize their parameters, you can do so by adding the following to your Zed settings file ([how to edit](../configuring-zed.md#settings-files)):
857
858```json [settings]
859{
860  "language_models": {
861    "x_ai": {
862      "api_url": "https://api.x.ai/v1",
863      "available_models": [
864        {
865          "name": "grok-1.5",
866          "display_name": "Grok 1.5",
867          "max_tokens": 131072,
868          "max_output_tokens": 8192
869        },
870        {
871          "name": "grok-1.5v",
872          "display_name": "Grok 1.5V (Vision)",
873          "max_tokens": 131072,
874          "max_output_tokens": 8192,
875          "supports_images": true
876        }
877      ]
878    }
879  }
880}
881```
882
883## Custom Provider Endpoints {#custom-provider-endpoint}
884
885You can use a custom API endpoint for different providers, as long as it's compatible with the provider's API structure.
886To do so, add the following to your settings file ([how to edit](../configuring-zed.md#settings-files)):
887
888```json
889{
890  "language_models": {
891    "some-provider": {
892      "api_url": "http://localhost:11434"
893    }
894  }
895}
896```
897
898Currently, `some-provider` can be any of the following values: `anthropic`, `google`, `ollama`, `openai`.
899
900This is the same infrastructure that powers models that are, for example, [OpenAI-compatible](#openai-api-compatible).