Skip to content

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.

View as Markdown

Call Claude, GPT or Mistral from your app without exposing the API key: calling Claude, GPT or Mistral with Claude Code, Cursor or Codex, on while, hosted in France

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:

The message to give your AI
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:

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.

Calling Claude, GPT or Mistral with while: credentials kept out of the AI's reach, every call logged in the history, a person's approval for what matters and a daily backup, in France
Around every app, while keeps the credentials, the history, the approvals and the backups.

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

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

Questions

Can my AI see the key?

No. You enter it in while, never in your AI 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.

Where do my app and its data run?

In France, at Nextmap. The database is backed up every day, with a way back over 14 days, once a person approves.

Give your AI the message, and it takes care of the rest

Give this to your AI

Read while.sh/agents and help me get started with while.

Copy the message

In 3 minutes, with no sign-up, the tool has its own address. To keep it, create your account.

For a company project, write to the while team: hello@while.sh