Skip to content

Call Claude, GPT or Mistral from your app without exposing the key, with your AI agent

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 agent connects it all over MCP.

By Aloïs Oddon, co-founder of Nextmap. Facts checked on November 2, 2026.

View as Markdown

Prerequisites

  • An app, deployed on while or ready to be.
  • The key from your AI provider: Anthropic, OpenAI or Mistral.
  • An AI agent that works in a terminal: Claude Code, Codex, Cursor or Gemini CLI.

Step 1: Give your agent these instructions

Open your agent in your app’s folder, and paste these instructions into it:

Instructions
Connect to while with my account (while.sh/agents), then deploy my app.

Your agent 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 agent declares the connection to Anthropic and gives you a link. You open it, paste the key and approve. Your agent never sees it.

What your agent does

It adds the connection to the service, in while.yaml:

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:

server.js
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 agent: Switch the summaries to Claude Haiku, so we pay less.

Your agent changes the model in your code and deploys again. The key stays as it is.

Change the key

You, to your agent: 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 agent: Why did the summaries fail last night?

Your agent reads the latest call and the calls the connection refused in while, and fixes the problem.

Add a second provider

You, to your agent: Connect Mistral too, as a backup.

Your agent 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 agent: Go back to the previous version.

In the 30 minutes after a deployment, the previous version comes back in a second. After that, it takes a few seconds. Once the previous version is back, your agent reads what broke in while’s logs, fixes it and deploys again.

In the docs: API connections and Versions and rollback.

Next steps

Sources

  1. Anthropic, the Messages API, accessed November 2, 2026

Questions

Can my agent see the key?

No. You enter it in while, never in your agent or in your code, and it is added to each call.

Which providers work?

Anthropic, OpenAI and Mistral, and any other HTTP API with its key.

Do I need to change my code?

Barely: your app calls the address it receives in ANTHROPIC_URL instead of Anthropic’s, and it no longer sends a key.

What if someone steals my app’s code?

The key isn’t in it: they can’t use it anywhere else.

Connect your agent, it takes care of the rest

To paste into your agent

Read while.sh/agents, then deploy my app with while.

Copy the instructions

No account needed to try: your app is live right away. To keep it, sign in.

A project for your company? Talk to the team: hello@while.sh