Use your own AI key
Use a key from OpenAI, Google, Anthropic or xAI to pay that provider directly for AI usage. This option is called BYOK (bring your own key).
Agents use Platica's account by default. When you connect your key, that provider's models use your account. You can also choose models that require your own key.
Before you start
You need:
- Your Platica API key in
PLATIC_API_KEY. - A key from one of the four providers.
- An agent with its id in
AGENT_ID.
To use the platform, see Models and your own keys.
See the providers
List all four providers, their states (
statusandhealth) and their models. They appear even if you haven't connected a key. (List providers)curl https://api.platic.ai/v1/ai-providers \ -H "Authorization: Bearer $PLATIC_API_KEY"import { Platic } from "platic-sdk"; const platic = new Platic({ apiKey: process.env.PLATIC_API_KEY! }); const providers = await platic.aiProviders.list(); for (const provider of providers) console.log(provider.provider, provider.status, provider.health);Which AI providers do I have connected with my own key?
Tool:
list_ai_providers.statusisnot_connected(it uses Platica's account),verifying,connected,invalidordisabled. In each model,ownKeyOnly: truemeans it only works with your own key.Connect your key
Connect the key to store and test it. If the provider already had a key, this call replaces it. You don't need to send the key in later reads. (Connect a key)
curl -X PUT https://api.platic.ai/v1/ai-providers/openai \ -H "Authorization: Bearer $PLATIC_API_KEY" \ -H "Content-Type: application/json" \ -d '{ "value": "'$OPENAI_API_KEY'", "fallback": "platform" }'const openai = await platic.aiProviders.connect("openai", { value: process.env.OPENAI_API_KEY!, fallback: "platform", }); if (openai.status !== "connected") { console.log(openai.health, openai.lastError); }I want to use my own OpenAI key.
Tool:
connect_ai_provider. To keep the key out of the chat, connect it yourself in Settings → Models and ask your assistant to check it.providerisopenai,google,anthropicorxai, and the key can be up to 4,096 characters. The key is stored encrypted as a workspace secret and no read returns it: onlystatus,health,fallback,secretNameandmodels.When you connect the key, Platica generates a short response with each model. The test uses a few tokens and can take up to 200 seconds. The limit is 10 tests per hour per provider.
If the key is invalid, the call returns
200withstatus: "invalid"and the reason inlastError.Choose the fallback
If you top up your balance, activate a model or the key becomes
invalid, you can test the stored key again without sending it. (Test a key)curl -X POST https://api.platic.ai/v1/ai-providers/openai/verify \ -H "Authorization: Bearer $PLATIC_API_KEY"const checked = await platic.aiProviders.verify("openai"); console.log(checked.status, checked.health, checked.lastError);Test my OpenAI key again.
Tool:
verify_ai_provider.healthcan beok,key_rejected,no_creditorno_model_access. Withno_credit, Platica retries every 10 minutes and resumes using the key when you top up.The fallback defines what to do if your key fails:
platform, the default, uses Platica's account and incurs AI charges. Models that require your own key stop responding.nonestops responses from that provider's models.
You can change the fallback without replacing the key. (Change the fallback)
curl -X PATCH https://api.platic.ai/v1/ai-providers/openai \ -H "Authorization: Bearer $PLATIC_API_KEY" \ -H "Content-Type: application/json" \ -d '{ "fallback": "none" }'await platic.aiProviders.update("openai", { fallback: "none" });If my OpenAI key fails, don't fall back to Platica's account.
Tool:
update_ai_provider.Choose the agent's model
Change
modelin the agent's draft and publish the version.To add fallback models, set
fallbackModelswithprovider/modelvalues. If you add a fallback the agent didn't have, you need at least one own key withstatus: "connected". Without it, you get422withMODEL_FALLBACKS_REQUIRE_OWN_KEY. (Update the draft, Agent configuration)curl -X PATCH https://api.platic.ai/v1/agents/$AGENT_ID/draft \ -H "Authorization: Bearer $PLATIC_API_KEY" \ -H "Content-Type: application/json" \ -d '{ "model": "claude-sonnet-5-5-medium" }' curl -X POST https://api.platic.ai/v1/agents/$AGENT_ID/publication \ -H "Authorization: Bearer $PLATIC_API_KEY"const agentId = process.env.AGENT_ID!; await platic.agents.draft.update(agentId, { model: "claude-sonnet-5-5-medium" }); await platic.agents.publish(agentId);Make the Sales agent use Claude Sonnet 5.5 with medium reasoning, and publish it.
Tool:
update_agent_draftandpublish_agent_version.The model can carry the reasoning level as a suffix (
claude-sonnet-5-5-medium). A level the model doesn't accept answers422withUNSUPPORTED_REASONING_EFFORT, and an unknown model,INVALID_CONFIG. This example assumes you connected an Anthropic key; use a model of the provider you connected.
Check it worked
Use List providers to check that your provider has status: "connected" and health: "ok", and the models you need are available. Send a message with Talk to your agent and check usage in your provider account.
To receive provider health changes, use the model_provider.status.updated webhook. See Receive webhooks.
To remove the key, disconnect it. Before, check which agents or models depend on it: they lose that workspace key.
Using your own key doesn't remove other Platica charges. Review Usage and your provider's billing.
Next steps
- Test it before you publish: compare the draft with the published version after changing the model.
- AI providers: states, errors and limits.
- Agent configuration: reasoning levels and fallback models.