You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
@@ -45,72 +45,6 @@ You can customize the base URL for any provider by setting the `baseURL` option.
45
45
46
46
---
47
47
48
-
## Troubleshooting
49
-
50
-
### Credential Loop Issue
51
-
52
-
If you're stuck in a credential loop when adding a custom provider (like Cerebras), this usually happens when the provider configuration is incomplete. Here's how to fix it:
53
-
54
-
1.**Complete the auth setup**: Make sure you've successfully added the credential using `opencode auth login` and selected **Other**.
55
-
56
-
2.**Configure the provider**: The credential alone isn't enough. You must also configure the provider in your `opencode.json` file with the correct `npm` package, `baseURL`, and models.
57
-
58
-
3.**Use the correct npm package**:
59
-
- For Cerebras: Use `@ai-sdk/cerebras` (not `@ai-sdk/openai-compatible`)
60
-
- For most other OpenAI-compatible providers: Use `@ai-sdk/openai-compatible`
61
-
62
-
4.**Example working configuration**:
63
-
```json title="opencode.json"
64
-
{
65
-
"$schema": "https://opencode.ai/config.json",
66
-
"model": "cerebras/qwen-3-235b-a22b",
67
-
"provider": {
68
-
"cerebras": {
69
-
"npm": "@ai-sdk/cerebras",
70
-
"name": "Cerebras",
71
-
"options": {
72
-
"baseURL": "https://api.cerebras.ai/v1"
73
-
},
74
-
"models": {
75
-
"qwen-3-235b-a22b": {
76
-
"name": "Qwen-3-235b-a22b"
77
-
}
78
-
}
79
-
}
80
-
}
81
-
}
82
-
```
83
-
84
-
### Global vs Local Configuration
85
-
86
-
opencode looks for configuration in this order:
87
-
88
-
1.**Local config**: `./opencode.json` in your current project directory
If you want to use a provider globally, add the provider configuration to a local `opencode.json` file in each project where you want to use it. The credentials from the global auth file will be automatically used.
93
-
:::
94
-
95
-
**Best practice**:
96
-
- Store credentials globally using `opencode auth login`
97
-
- Store provider configurations locally in each project's `opencode.json`
98
-
99
-
### Common Configuration Mistakes
100
-
101
-
1.**Wrong npm package**: Using `@ai-sdk/openai-compatible` when a specific package exists (like `@ai-sdk/cerebras`)
102
-
103
-
2.**Missing baseURL**: Always include the correct API endpoint in the `options.baseURL` field
104
-
105
-
3.**Incomplete model configuration**: Make sure to define at least one model in the `models` object
106
-
107
-
4.**API key format**: Different providers use different API key prefixes:
108
-
- OpenAI: `sk-...`
109
-
- Cerebras: `csk-...`
110
-
- Anthropic: Uses OAuth (no manual key needed)
111
-
112
-
---
113
-
114
48
## Directory
115
49
116
50
Let's look at some of the providers in detail. If you'd like to add a provider to the
@@ -667,8 +601,6 @@ To add any **OpenAI-compatible** provider that's not listed in `opencode auth lo
667
601
You can use any OpenAI-compatible provider with opencode. Most modern AI providers offer OpenAI-compatible APIs.
668
602
:::
669
603
670
-
#### Step 1: Add Credentials
671
-
672
604
1. Run `opencode auth login` and scroll down to **Other**.
673
605
674
606
```bash
@@ -682,7 +614,7 @@ You can use any OpenAI-compatible provider with opencode. Most modern AI provide
682
614
└
683
615
```
684
616
685
-
2. Enter a unique ID for the provider (use lowercase, no spaces).
617
+
2. Enter a unique ID for the provider.
686
618
687
619
```bash
688
620
$ opencode auth login
@@ -695,7 +627,7 @@ You can use any OpenAI-compatible provider with opencode. Most modern AI provide
695
627
```
696
628
697
629
:::note
698
-
Choose a memorable ID - you'll use this in your config file.
630
+
Choose a memorable ID, you'll use this in your config file.
699
631
:::
700
632
701
633
3. Enter your API key for the provider.
@@ -712,19 +644,60 @@ You can use any OpenAI-compatible provider with opencode. Most modern AI provide
712
644
└
713
645
```
714
646
715
-
#### Step 2: Configure Provider
647
+
4. Create or update your `opencode.json` file in your project directory:
- **npm**: AI SDK package to use, `@ai-sdk/openai-compatible`for OpenAI-compatible providers
672
+
- **name**: Display name in UI.
673
+
- **models**: Available models.
674
+
- **options.baseURL**: API endpoint URL.
675
+
- **options.apiKey**: Optionally set the API key, if not using auth.
676
+
- **options.headers**: Optionally set custom headers.
677
+
678
+
More on the advanced options in the example below.
679
+
680
+
5. Run the `/models`command and your custom provider and models will appear in the selection list.
681
+
682
+
---
683
+
684
+
##### Example
716
685
717
-
Create or update your `opencode.json` file in your project directory:
686
+
Here's an example setting the `apiKey` and `headers` options.
718
687
719
-
```json title="opencode.json""myprovider" {5-15}
688
+
```json title="opencode.json" {9,11}
720
689
{
721
690
"$schema": "https://opencode.ai/config.json",
722
691
"provider": {
723
692
"myprovider": {
724
693
"npm": "@ai-sdk/openai-compatible",
725
-
"name": "My AI Provider",
694
+
"name": "My AI ProviderDisplay Name",
726
695
"options": {
727
-
"baseURL": "https://api.myprovider.com/v1"
696
+
"baseURL": "https://api.myprovider.com/v1",
697
+
"apiKey": "{env:ANTHROPIC_API_KEY}",
698
+
"headers": {
699
+
"Authorization": "Bearer custom-token"
700
+
}
728
701
},
729
702
"models": {
730
703
"my-model-name": {
@@ -736,15 +709,7 @@ Create or update your `opencode.json` file in your project directory:
736
709
}
737
710
```
738
711
739
-
#### Configuration Options
740
-
741
-
| Field | Description | Required |
742
-
|-------|-------------|----------|
743
-
|`npm`| AI SDK package to use | ✅ |
744
-
|`name`| Display name in UI | ✅ |
745
-
|`options.baseURL`| API endpoint URL | ✅ |
746
-
|`models`| Available models | ✅ |
747
-
|`options.apiKey`| API key (if not using auth) | ❌ |
712
+
We are setting the `apiKey` using the `env` variable syntax, [learn more](/docs/config#env-vars).
748
713
749
714
#### Common Examples
750
715
@@ -789,46 +754,19 @@ Create or update your `opencode.json` file in your project directory:
789
754
}
790
755
}
791
756
```
757
+
---
792
758
793
-
**Local API (with custom headers):**
794
-
```json title="opencode.json"
795
-
{
796
-
"$schema": "https://opencode.ai/config.json",
797
-
"provider": {
798
-
"local": {
799
-
"npm": "@ai-sdk/openai-compatible",
800
-
"name": "Local API",
801
-
"options": {
802
-
"baseURL": "http://localhost:8000/v1",
803
-
"headers": {
804
-
"Authorization": "Bearer custom-token"
805
-
}
806
-
},
807
-
"models": {
808
-
"local-model": {
809
-
"name": "Local Model"
810
-
}
811
-
}
812
-
}
813
-
}
814
-
}
815
-
```
816
-
817
-
#### Step 3: Select Model
818
-
819
-
Run the `/models`command to selectyour custom provider's model:
759
+
## Troubleshooting
820
760
821
-
```bash
822
-
$ opencode
823
-
> /models
824
-
```
761
+
If you are having trouble with configuring a provider, check the following:
825
762
826
-
Your custom provider and models will appear in the selection list.
763
+
1. **Check the auth setup**: Run `opencode auth list` to see if the credentials
764
+
for the provider are added to your config.
827
765
828
-
#### Tips
766
+
This doesn't apply to providers like Amazon Bedrock, that rely on environment variables for their auth.
829
767
830
-
- **Provider ID**: Use lowercase letters and hyphens only (e.g., `my-provider`)
831
-
- **Model names**: Use the exact model ID from the provider's API documentation
832
-
- **Base URL**: Always include the full path (usually ending in`/v1`)
833
-
- **Testing**: Start with one model to test the configuration before adding more
768
+
2. For custom providers, check the opencode config and:
834
769
770
+
- Make sure the provider ID used in`opencode auth login` matches the ID in your opencode config.
771
+
- The right npm package is used for the provider. For example, use `@ai-sdk/cerebras`for Cerebras. And for all other OpenAI-compatible providers, use `@ai-sdk/openai-compatible`.
772
+
- Check correct API endpoint is used in the `options.baseURL` field.
0 commit comments