Setup
We assume you have some idea about how Bifrost works and you have already set up bifrost for local development.Provider structure
Bifrost is a gateway, meaning it receives request in a standard format (OpenAI compatible), converts it to provider specific formats and sends the request. It then receives the provider response and converts it back to the standard (OpenAI compatible) response. To implement a new provider, you must roughly follow these steps:- Define provider specific types, like
ProviderSpeechRequestorProviderChatCompletionRequest, etc. - Implement conversion functions from Bifrost request / response to provider specific request / response and vice versa.
- Implement the handler functions for the type of request you want to handle. For example, to handle chat completion requests, you need to implement
ChatCompletionfunctions. You can check the full list of handlers here.
core/providers/openai/types.go for an example).
OpenAI Compatible Providers
If you are implementing a provider for an OpenAI API compatible API, you can use theopenai package from core/providers/openai. (See cerebras provider as an example.)
File conventions
If the provider is OpenAI compatible, a singleprovider/[provider_name].go file is enough.
If the provider is not OpenAI compatible, you need to create a new folder and add the following files. Not all of them are required. Add the ones that are relevant to your provider.
Extra fields
When parsing request, all non standard fields are stored inParams.ExtraParams map. This is useful for providers that require additional fields that are not part of OpenAI API. (See perplexity provider as an example).
Local testing
Once you’re done writing the provider, you may want to test it locally before writing some automated tests. We will setup a new go project and import our provider.github.com/maximhq/bifrost/core with your local path to the core (relative path).
Adding automated tests
Create a new file intests/core-providers directory and enable tests for all the provider function you have implemented (like Speech, SpeechStream, Embeddings, etc.).
