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
TheProviderConfig class has the following properties.
Basic usage
When using a custom provider, themodel parameter is required.
Ollama (local provider)
Local providers like Ollama don’t need anapiKey.
Azure OpenAI
For Azure OpenAI, keep the following in mind.- Set
typetoazure(notopenai). - Set
baseUrlto the host only (do not include paths like/openai/v1).
Azure Managed Identity
UsebearerTokenProvider 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.
Important notes
- Always use
type: 'azure'for Azure endpoints (*.openai.azure.com). - Specify
baseUrlas the host only. The SDK builds the path automatically.
The onListModels handler
When using a custom provider in BYOK mode, you can configureclient->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().
null clears the handler and restores the default CLI server behavior.
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.