Skip to content

Commit 9778e86

Browse files
Copilotfriggeri
andcommitted
Add comprehensive Azure provider documentation to .NET SDK README
Co-authored-by: friggeri <106686+friggeri@users.noreply.github.com>
1 parent dcfbe17 commit 9778e86

File tree

1 file changed

+56
-3
lines changed

1 file changed

+56
-3
lines changed

dotnet/README.md

Lines changed: 56 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -430,20 +430,73 @@ await session.SendAsync(new MessageOptions
430430

431431
### Bring Your Own Key (BYOK)
432432

433-
Use a custom API provider:
433+
The SDK supports custom OpenAI-compatible API providers (BYOK - Bring Your Own Key), including local providers like Ollama. When using a custom provider, you must specify the `Model` explicitly.
434+
435+
**ProviderConfig fields:**
436+
437+
- `Type` (string): Provider type - `"openai"`, `"azure"`, or `"anthropic"` (default: `"openai"`)
438+
- `BaseUrl` (string): API endpoint URL (required)
439+
- `ApiKey` (string): API key (optional for local providers like Ollama)
440+
- `BearerToken` (string): Bearer token for authentication (takes precedence over `ApiKey`)
441+
- `WireApi` (string): API format for OpenAI/Azure - `"completions"` or `"responses"` (default: `"completions"`)
442+
- `Azure` (AzureProviderOptions): Azure-specific options with `ApiVersion` (default: `"2024-10-21"`)
443+
444+
**Example with Ollama:**
445+
446+
```csharp
447+
var session = await client.CreateSessionAsync(new SessionConfig
448+
{
449+
Model = "deepseek-coder-v2:16b", // Required when using custom provider
450+
Provider = new ProviderConfig
451+
{
452+
Type = "openai",
453+
BaseUrl = "http://localhost:11434/v1", // Ollama endpoint
454+
// ApiKey not required for Ollama
455+
}
456+
});
457+
458+
await session.SendAsync(new MessageOptions { Prompt = "Hello!" });
459+
```
460+
461+
**Example with custom OpenAI-compatible API:**
434462

435463
```csharp
436464
var session = await client.CreateSessionAsync(new SessionConfig
437465
{
466+
Model = "gpt-4",
438467
Provider = new ProviderConfig
439468
{
440469
Type = "openai",
441-
BaseUrl = "https://api.openai.com/v1",
442-
ApiKey = "your-api-key"
470+
BaseUrl = "https://my-api.example.com/v1",
471+
ApiKey = Environment.GetEnvironmentVariable("MY_API_KEY")
472+
}
473+
});
474+
```
475+
476+
**Example with Azure OpenAI:**
477+
478+
```csharp
479+
var session = await client.CreateSessionAsync(new SessionConfig
480+
{
481+
Model = "gpt-4",
482+
Provider = new ProviderConfig
483+
{
484+
Type = "azure", // Must be "azure" for Azure endpoints, NOT "openai"
485+
BaseUrl = "https://my-resource.openai.azure.com", // Just the host, no path
486+
ApiKey = Environment.GetEnvironmentVariable("AZURE_OPENAI_KEY"),
487+
Azure = new AzureProviderOptions
488+
{
489+
ApiVersion = "2024-10-21"
490+
}
443491
}
444492
});
445493
```
446494

495+
> **Important notes:**
496+
> - When using a custom provider, the `Model` parameter is **required**. The SDK will throw an error if no model is specified.
497+
> - For Azure OpenAI endpoints (`*.openai.azure.com`), you **must** use `Type = "azure"`, not `Type = "openai"`.
498+
> - The `BaseUrl` should be just the host (e.g., `https://my-resource.openai.azure.com`). Do **not** include `/openai/v1` in the URL - the SDK handles path construction automatically.
499+
447500
## Error Handling
448501

449502
```csharp

0 commit comments

Comments
 (0)