|
| 1 | +--- |
| 2 | +title: "BYO OpenAI-compatible model" |
| 3 | +pageOrder: 7 |
| 4 | +description: "Bring your own OpenAI-compatible model to kagent." |
| 5 | +--- |
| 6 | + |
| 7 | +export const metadata = { |
| 8 | + title: "BYO OpenAI-compatible model", |
| 9 | + description: "Bring your own OpenAI-compatible model to kagent.", |
| 10 | + author: "kagent.dev" |
| 11 | +}; |
| 12 | + |
| 13 | +You can bring your own model from an [OpenAI API-compatible](https://platform.openai.com/docs/api-reference/introduction) LLM provider. The example integrates with [Cohere AI](https://cohere.com/). |
| 14 | + |
| 15 | +1. Save your API key from the OpenAI-compatible provider as an environment variable. For example, navigate to the [Cohere AI dashboard](https://dashboard.cohere.com/api-keys). |
| 16 | + |
| 17 | + ```bash |
| 18 | + export PROVIDER_API_KEY=Dgs... |
| 19 | + ``` |
| 20 | + |
| 21 | +2. Create a Kubernetes secret that stores your API key. Make sure to create the secret in the same namespace as you plan to create your agent, such as `kagent`. |
| 22 | + |
| 23 | + ```bash |
| 24 | + kubectl create secret generic kagent-my-provider -n kagent --from-literal PROVIDER_API_KEY=$PROVIDER_API_KEY |
| 25 | + ``` |
| 26 | + |
| 27 | +3. Create a ModelConfig resource. |
| 28 | + |
| 29 | + ```yaml |
| 30 | + kubectl apply -f - <<EOF |
| 31 | + apiVersion: kagent.dev/v1alpha2 |
| 32 | + kind: ModelConfig |
| 33 | + metadata: |
| 34 | + name: my-provider-config |
| 35 | + namespace: kagent |
| 36 | + spec: |
| 37 | + apiKeySecret: kagent-my-provider |
| 38 | + apiKeySecretKey: PROVIDER_API_KEY |
| 39 | + model: command-a-03-2025 |
| 40 | + provider: OpenAI |
| 41 | + openAI: |
| 42 | + baseUrl: "https://api.cohere.ai/compatibility/v1" |
| 43 | + EOF |
| 44 | + ``` |
| 45 | + |
| 46 | + Review the following table to understand this configuration. For more information, see the [API docs](https://kagent.dev/docs/kagent/resources/api-ref#openaiconfig). |
| 47 | + |
| 48 | + | Setting | Description | |
| 49 | + | --- | --- | |
| 50 | + | `apiKeySecret` | The name of the Kubernetes secret that stores your API key. | |
| 51 | + | `apiKeySecretKey` | The key in the secret that stores your API key. | |
| 52 | + | `model` | The OpenAI API-compatible model to use. For more information about the model, consult your LLM provider's documentation. For example, you might use `command-a-03-2025` for [Cohere AI](https://docs.cohere.com/v1/docs/models). | |
| 53 | + | `provider` | To use an OpenAI API-compatible model, set the provider to `OpenAI`. | |
| 54 | + | `openAI` | Additional provider details. For available settings, consult your LLM provider's documentation. At the least, you must configure the `baseUrl` setting to point to the endpoint of your LLM provider. | |
| 55 | + | `baseUrl` | The base URL of your LLM provider. Note that the LLM provider might have a special base URL for OpenAI compatibility, such as `"https://api.cohere.ai/compatibility/v1"` for [Cohere AI](https://cohere.com/). | |
| 56 | + |
| 57 | +Good job! You added a model to kagent. Next, you can [create or update an agent](https://kagent.dev/docs/kagent/getting-started/first-agent) to use this model. |
0 commit comments