Use your own API key: BYOK and custom providers
What BYOK is
BYOK stands for “Bring Your Own Key”. You sign up with a model provider (such as OpenAI, DeepSeek or OpenRouter), create an API key there, add it to 主公, and then pick your own models right in the chat.
When it helps
- You already have an account and credit with a provider and want to keep using it in 主公.
- The model you want isn’t one of the default options.
- You want to decide which model you use and which provider bills you.
When you chat with one of your own models, the request goes to that provider with your key, and the provider charges your account with them under their own pricing.
Before you start
You need Pro or Max
Adding and using your own models needs an active paid plan (Pro or Max). On the free plan, the AI providers tab shows AI providers require a paid plan and Upgrade to Pro or Max to add and use your own models. Click Upgrade plan to choose a plan.
Have three things ready
- An API key: create one in your provider’s dashboard.
- Model IDs: the exact model names from your provider’s docs.
- A base URL (custom providers only): the OpenAI-compatible API address your provider gives you.
Adding a provider
Open settings
- Click your avatar in the bottom-left corner, or click your name (the row with the ⋯) and choose Account and workspace settings.
- Switch to the AI providers tab. You’ll see Personal AI providers.
- Click Add provider.
Fill in the form
- Display name: a name you’ll recognize. The chat groups your models under this name.
- Provider kind: there are three.
- OpenAI preset: the base URL is fixed to
https://api.openai.com/v1. - DeepSeek preset: the base URL is fixed to
https://api.deepseek.com. - Custom OpenAI-compatible: works with any service that offers an OpenAI-compatible API. You enter the base URL yourself.
- OpenAI preset: the base URL is fixed to
- Base URL: filled in and locked for presets. For a custom provider, enter the address your provider gives you, usually ending in
/v1. 主公 adds/chat/completionsto the end for you. It must be a public address starting withhttps://.localhostand private network addresses aren’t supported. - Models: your model IDs, separated by commas. Up to 100, no duplicates. Presets fill in a few for you, but providers rename models over time, so check your provider’s docs and change the list to the ones you want.
- Default model: pick one from your list. It’s the one used when you test the connection.
- API credential: paste your key.
Test and save
- Click Test connection first. 主公 sends a very short test message with your key and default model. If it works you’ll see Connected successfully (…ms).
- If all looks good, click Add provider to save.
Once saved, the list shows the provider’s status, credential (Saved) and default model. Each card also has a test bar where you can type a model ID and click Test connection at any time. To change settings, click Edit. The API credential box says Leave blank to keep existing credential, so you only fill it in when you want to switch keys.
Picking your model in chat
- Click New chat and find the button next to the message box that reads something like Auto · Medium (Model and effort).
- Under Model, below Auto (which uses the workspace default model), your models are listed in groups named after each provider’s display name.
- Once you pick one, the button shows “Display name — model ID”.
A few things to know:
- The model is locked once the conversation starts. You’ll see Model locked for this conversation. Start a new chat to change it. To switch models, start a new chat.
- In the same browser, new chats remember the model you picked last time. If that provider was deleted or the model is gone, it goes back to Auto.
- If you’ve picked an agent, the agent decides the model, and the button says Model and effort are controlled by the selected agent.
- Manage personal providers… at the bottom of the panel takes you straight to settings.
Example: connect OpenRouter
OpenRouter lets one key call models from many companies, and it offers an OpenAI-compatible API, so it’s a good fit for Custom OpenAI-compatible.
- Create an API key on the OpenRouter website.
- In 主公, click Add provider and fill it in like this:
| Field | What to enter |
|---|---|
| Display name | OpenRouter |
| Provider kind | Custom OpenAI-compatible |
| Base URL | https://openrouter.ai/api/v1 |
| Models | deepseek/deepseek-v4-pro, google/gemini-3.5-flash |
| Default model | deepseek/deepseek-v4-pro |
| API credential | sk-... (use your own key) |
- Click Test connection. When you see Connected successfully, click Add provider.
- Start a new chat, find the OpenRouter group under Model, and pick a model.
The model IDs above are only examples. Use the names exactly as they appear in OpenRouter’s model list. For DeepSeek, just choose DeepSeek preset and the base URL is filled in for you. Check the model names against DeepSeek’s docs.
Troubleshooting
Form messages
- Display name is required to test connection, API credential is required to test connection, Please select or enter a model to test: that field is still empty.
- Base URL is required for custom provider: you chose the custom kind but left the base URL empty.
- A valid HTTPS base URL is required for a custom provider: the address doesn’t start with
https://, or it isn’t a valid URL.
Test connection fails
A short reason is shown in the form:
- Provider authentication failed: the key is wrong or no longer valid. Copy it again.
- Provider authorization failed: the key doesn’t have permission. Check its permissions or your balance with the provider.
- The provider rejected the selected model: the model ID is misspelled, or this key can’t use that model.
- The provider rate limit was reached: too many requests. Try again later.
- Provider request timed out: the provider was too slow. Try again later.
- The provider endpoint was rejected: the address isn’t allowed, for example it isn’t https or it’s a private network address.
- Provider network request failed: 主公 couldn’t reach the provider. Check the base URL.
Errors in chat
If you see Provider Unavailable (502 Bad Gateway) while chatting with your own model, the provider sent back a reply 主公 couldn’t understand. Try again, or start a new chat with a different model.
Keeping your key safe
- Your key is encrypted when it’s saved. After that the page only shows the credential as Saved and never shows the key again.
- Deleting a provider also deletes its saved key, and conversations locked to it can no longer use it.
- Create a separate key just for 主公, and set a spending limit with your provider.
- If you think a key has leaked, revoke it with your provider first, then come back, click Edit and paste a new one.
- Never paste keys into chats, documents or screenshots.
Next steps
- Recap: Core concepts
- Pick a template from the Template Center and try it with your own model.