Call Claude, GPT or Mistral from your app without exposing the API key (2026)
Your app talks to an AI model, and its key costs a lot if it leaks. With while, your app calls Claude, GPT or Mistral without ever holding the key, every call is recorded, and your AI connects it all over MCP.
By Aloïs Oddon, co-founder of Nextmap. Facts checked on November 19, 2026.
The short version. Your app calls Claude, GPT or Mistral without holding the key, which is kept in while. Your AI connects it all over MCP and never sees it. What matters, like deleting a database, waits for a person’s approval.
Prerequisites
- An app, deployed on while or ready to be.
- The key from your AI provider: Anthropic, OpenAI or Mistral.
- An AI that works in a terminal: Claude Code, Codex, Cursor or Gemini CLI.
Step 1: Give your AI this message
Open your AI in your app’s folder, and paste this message into it:
Connect to while with my account (while.sh/agents), then put my app on while.
Your AI adds while’s MCP server itself. If it asks you to, restart it. On the first call to while, a page opens in your browser. In Claude Code, if it doesn’t open, type /mcp, choose while, then Authenticate. On that page, choose “A new app”, then click Authorize.
Step 2: Paste the key into while
Your AI declares the connection to Anthropic and gives you a link. You open it, paste the key and approve. Your AI never sees it.
What your AI does
It adds the connection to the service, in while.yaml:
services:
- name: web
port: 3000
connections: [anthropic]
Your app receives while’s address for Anthropic in ANTHROPIC_URL, and calls the Messages API without a key1:
const r = await fetch(`${process.env.ANTHROPIC_URL}/v1/messages`, {
method: 'POST',
headers: { 'content-type': 'application/json' },
body: JSON.stringify({
model: 'claude-sonnet-5-5',
max_tokens: 1024,
messages: [{ role: 'user', content: question }],
}),
});
The key and the version header are added to each call, and every call is recorded. Calls to Claude go through from the first day, with no learning period.

Switch models
You, to your AI: Switch the summaries to Claude Haiku, so we pay less.
Your AI changes the model in your code and deploys again. The key stays as it is.
Change the key
You, to your AI: We need to change the Anthropic key.
You paste the new key into while, and your app uses it from the next call, with no new deployment.
See your app’s calls
You, to your AI: Why did the summaries fail last night?
Your AI reads the latest call and the calls the connection refused in while, and fixes the problem.
Add a second provider
You, to your AI: Connect Mistral too, as a backup.
Your AI declares a second connection and adds it to while.yaml, you paste its key into while, and your app receives MISTRAL_URL. The Pro plan includes up to 25 API connections.
Go back to the previous version
You, to your AI: Go back to the previous version.
In the 30 minutes after a production release, the previous version comes back in a second. After that, it takes a few seconds. Once the previous version is back, your AI reads what broke in while’s logs, fixes it and deploys again.
In the docs: API connections and Versions and rollback.
Next steps
Sources
- Anthropic, the Messages API, accessed November 2, 2026