Skip to main content

Custom providers

Custom providers (BYOK — Bring Your Own Key) let you connect to an OpenAI-compatible API endpoint with your own API key. Local providers such as Ollama are also supported.

ProviderConfig

The ProviderConfig class has the following properties.

Basic usage

When using a custom provider, the model parameter is required.
You can also specify it as an array.

Ollama (local provider)

Local providers like Ollama don’t need an apiKey.

Azure OpenAI

For Azure OpenAI, keep the following in mind.
  • Set type to azure (not openai).
  • Set baseUrl to the host only (do not include paths like /openai/v1).

Azure Managed Identity

Use bearerTokenProvider when your provider uses short-lived tokens, such as Azure Managed Identity. The runtime calls the callback on every provider request. The callback receives an array containing providerName and sessionId, and must return the bearer token as a string. The following example calls a token service in your application.
Handle token acquisition, caching, and refresh inside your callback.

Important notes

The model parameter is required when using a custom provider. Without it, the call errors out.
  • Always use type: 'azure' for Azure endpoints (*.openai.azure.com).
  • Specify baseUrl as the host only. The SDK builds the path automatically.

The onListModels handler

When using a custom provider in BYOK mode, you can configure client->listModels() to invoke a custom handler instead of the CLI server. Configure it with the listModelsUsing() method. Since the client is prone to being initialized before listModels() is called, always set listModelsUsing() before listModels().
Passing null clears the handler and restores the default CLI server behavior.
When listModelsUsing() is configured, listModels() does not need to connect to the CLI server and does not use a cache either.
For the latest updates, see the GitHub repository.
Last modified on October 19, 2026