Skip to content

Commit 58cc5cd

Browse files
authored
add support for azure cognitive services provider (sst#4397)
1 parent 3c6dcad commit 58cc5cd

File tree

2 files changed

+72
-0
lines changed

2 files changed

+72
-0
lines changed

packages/opencode/src/provider/provider.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,22 @@ export namespace Provider {
7878
options: {},
7979
}
8080
},
81+
"azure-cognitive-services": async () => {
82+
const resourceName = process.env["AZURE_COGNITIVE_SERVICES_RESOURCE_NAME"]
83+
return {
84+
autoload: false,
85+
async getModel(sdk: any, modelID: string, options?: Record<string, any>) {
86+
if (options?.["useCompletionUrls"]) {
87+
return sdk.chat(modelID)
88+
} else {
89+
return sdk.responses(modelID)
90+
}
91+
},
92+
options: {
93+
baseURL: resourceName ? `https://${resourceName}.cognitiveservices.azure.com/openai` : undefined,
94+
},
95+
}
96+
},
8197
"amazon-bedrock": async () => {
8298
if (!process.env["AWS_PROFILE"] && !process.env["AWS_ACCESS_KEY_ID"] && !process.env["AWS_BEARER_TOKEN_BEDROCK"])
8399
return { autoload: false }

packages/web/src/content/docs/providers.mdx

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -229,6 +229,62 @@ Or if you already have an API key, you can select **Manually enter API Key** and
229229

230230
---
231231

232+
### Azure Cognitive Services
233+
234+
1. Head over to the [Azure portal](https://portal.azure.com/) and create an **Azure OpenAI** resource. You'll need:
235+
- **Resource name**: This becomes part of your API endpoint (`https://AZURE_COGNITIVE_SERVICES_RESOURCE_NAME.cognitiveservices.azure.com/`)
236+
- **API key**: Either `KEY 1` or `KEY 2` from your resource
237+
238+
2. Go to [Azure AI Foundry](https://ai.azure.com/) and deploy a model.
239+
240+
:::note
241+
The deployment name must match the model name for opencode to work properly.
242+
:::
243+
244+
3. Run `opencode auth login` and select **Azure**.
245+
246+
```bash
247+
$ opencode auth login
248+
249+
┌ Add credential
250+
251+
◆ Select provider
252+
│ ● Azure Cognitive Services
253+
│ ...
254+
255+
```
256+
257+
4. Enter your API key.
258+
259+
```bash
260+
$ opencode auth login
261+
262+
┌ Add credential
263+
264+
◇ Select provider
265+
│ Azure Cognitive Services
266+
267+
◇ Enter your API key
268+
│ _
269+
270+
```
271+
272+
5. Set your resource name as an environment variable:
273+
274+
```bash
275+
AZURE_COGNITIVE_SERVICES_RESOURCE_NAME=XXX opencode
276+
```
277+
278+
Or add it to your bash profile:
279+
280+
```bash title="~/.bash_profile"
281+
export AZURE_COGNITIVE_SERVICES_RESOURCE_NAME=XXX
282+
```
283+
284+
6. Run the `/models` command to select your deployed model.
285+
286+
---
287+
232288
### Baseten
233289

234290
1. Head over to the [Baseten](https://app.baseten.co/), create an account, and generate an API key.

0 commit comments

Comments
 (0)