Mistral API key setup: workspaces, spending limits and why Free mode returns 402

Create a Mistral API key in Studio, store it as MISTRAL_API_KEY, turn on pay-as-you-go so calls stop failing with 402, and put a spending limit on it.

Simon, Founder of Shipyard

By · Founder of Shipyard

6 minute read

The short version

Sign in at console.mistral.ai, open API Keys at console.mistral.ai/api-keys, choose New key, give it a name and an expiry date, and copy it at once: Mistral shows the full key only once. Store it on your host as MISTRAL_API_KEY and call https://api.mistral.ai/v1 from server code with the @mistralai/mistralai package. Then sort out billing before you test. On the default Free mode you can create a key, but every model request fails with HTTP 402 until you turn on pay-as-you-go with prepaid credits or move to a plan that includes API usage.

Mistral is the natural pick when you want a European provider: its help centre says your data is hosted in the European Economic Area by default. Its small model is also cheap, at $0.15 per million input tokens and $0.60 per million output tokens for Mistral Small 4, and you can put a spending limit on a single key, not just on the whole account.

Why a new key returns 402

This catches out anyone following an older tutorial. Mistral's usage documentation now says Free mode includes a monthly allowance for trying Vibe and Studio, but no API usage. Keys can still be created on it, so the key looks fine, yet requests fail with HTTP 402 and code 2314, "You need a subscription to access this API." Guides that describe a free API tier for experiments describe a setup that no longer applies. A related clue: if a 429 response carries an x-ratelimit-limit-req-minute header of 0, the organization is still on Free mode.

The fix sits with an admin or billing member of the organization. Add prepaid credits under Admin Panel, Billing, Billing, which is required before pay-as-you-go can be turned on. The same page has an Auto Recharge section that charges your card and tops the balance up when it falls below a threshold you choose. Pro, Team and Education plans include API usage, and pay-as-you-go extends them past the included amount. Every 402 carries a code that names the exact money problem:

CodeWhat it meansWhat to do
402, code 2314The plan has no API usage (Free mode)Turn on pay-as-you-go with a positive balance, or use a plan with API usage
402, code 2308Out of creditsAdd credits, or turn on Auto Recharge
402, code 2300The monthly overage cap was reachedAsk an admin to raise the cap, or wait for next month
402, codes 2309 to 2313A spending limit you set was reachedWait for it to reset, or ask an admin to raise it
401Invalid API KeyMissing, wrong, revoked or expired key. Billing problems never return 401

Create the key, step by step

Once the key is on your host, this request from your own terminal is the quickest proof that both the key and the billing are right. A JSON answer with the reply in choices[0].message.content means you are done. A 401 means the variable does not hold the full key; a 402 sends you back to the table above.

  1. In the Admin Panel, create one workspace per environment, for example myapp-dev and myapp-prod. Mistral recommends a separate workspace and key for each.
  2. Add credits under Billing and turn on pay-as-you-go, or confirm your plan already includes API usage.
  3. Open API Keys at console.mistral.ai/api-keys, choose New key, select the workspace, then set a name, an expiry date and the connector access scope. Leave the scope on Shared connectors only.
  4. Copy the key into your host's environment variables as MISTRAL_API_KEY straight away. Mistral will not show it again.
  5. Under Admin Panel, Billing, Limits, add a monthly spending limit for the production workspace or for the key itself, with your email as a recipient.
Terminal
curl https://api.mistral.ai/v1/chat/completions \
  -H "Authorization: Bearer $MISTRAL_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"model": "mistral-small-latest", "messages": [{"role": "user", "content": "Say hello"}]}'

Three settings you cannot change later

A Mistral key is tied to one workspace and uses that workspace's resources. The workspace, the expiry date and the connector access scope are all fixed when you create the key. There is no edit button: to change any of them, you create a new key and delete the old one, so it pays to choose carefully the first time.

For an app, keep the default scope, Shared connectors only. The other option, Private and shared connectors, also lets the key use connectors that belong privately to the person who created it, which a web server has no reason to touch. For expiry, a dated key is safer than a non-expiring one, but an expired key fails with 401 like a wrong one, so put the date in your calendar along with a reminder to rotate. Organization admins can also enforce a maximum lifetime for every new key, and that rule applies only to keys created after it is set.

Spending limits and rate limits

Mistral lets you cap spend at four levels: the organization, a workspace, a user or a single API key. A workspace limit can count all usage, only API usage, or only Vibe and Studio, and a workspace can carry several limits at once, such as one daily and one monthly. When a limit is reached, requests in that workspace fail with 402 until it resets or an admin raises it, while other workspaces carry on. That is finer control than DeepSeek, where only the prepaid balance stops the spend, and similar to the credit limit OpenRouter puts on each key.

Rate limits are set per model and shared by the whole organization: requests per second, tokens per minute and tokens per month. They rise with what you have been billed. Turning on pay-as-you-go gives Tier 1, and Mistral moves you up automatically once your billed total passes $20, $100 and $500, with higher limits on request above $2,000. Buying credits alone does not raise your tier. A 429 with code 1300 means you hit your own limit, so back off and retry; codes 3505 and 3801 mean Mistral is short of capacity for that model, so retry later or use another model for a while. Your current numbers are on the Limits page of the Admin Panel.

Call Mistral from the server

The official TypeScript SDK is @mistralai/mistralai. It is an ES module, so a plain Node project needs "type": "module" in package.json; Next.js handles that for you. Read the model from a variable. mistral-small-latest is an alias that currently points to Mistral Small 4, with a 256K token context, and an alias can move to a newer version without warning. That is handy while prototyping and risky once you depend on the output, so switch to the dated name, mistral-small-2603, before you launch.

If most of your users are in the US and you want their requests processed there, Mistral offers a separate US API endpoint. Without it, data stays in the European Economic Area by default, which is the point for many teams choosing Mistral, so only switch if you have a reason to.

TypeScript
// app/api/ask/route.ts
import { Mistral } from '@mistralai/mistralai'

const mistral = new Mistral({ apiKey: process.env.MISTRAL_API_KEY })

export async function POST(req: Request) {
  // Check the session and a per-user rate limit here.
  const { question } = await req.json()
  const res = await mistral.chat.complete({
    model: process.env.MISTRAL_MODEL ?? 'mistral-small-2603',
    messages: [{ role: 'user', content: question }],
  })
  const content = res.choices?.[0]?.message?.content
  return Response.json({ text: typeof content === 'string' ? content : '' })
}

If the key leaks

Delete the key from API Keys in Studio, or as an admin under Admin Panel, API, API Keys, then create a replacement in the same workspace and update MISTRAL_API_KEY on your host. Check Admin Panel, API, Usage for the days the key was exposed. How much a leak can cost depends on what you set up earlier: a spending limit on the key or workspace stops it at that amount, prepaid credits without Auto Recharge stop it when they run out, and Auto Recharge with no limit leaves only your card in the way. Set the limit before launch, not after the first surprise.

What Shipyard does here

Today Shipyard's AI step writes only Anthropic, OpenAI or OpenRouter keys into your host. Mistral is not on that list, so after a launch you add MISTRAL_API_KEY and MISTRAL_MODEL to the host yourself, using the steps above. If you would rather keep one key for several labs, OpenRouter also serves Mistral models; choose it as the provider and Shipyard writes that key into your host, on the server side only.

Sources

Launch in an hour, not a weekend

Shipyard connects your accounts once, then sets up the domain, hosting, database, email and payments for every new product.

Get started See how it works

Read next