Module 5 · step 5 of 6 · Deploying and testing

API keys, API and MCP

Let your own code call the model: create a predict-only API key, read the endpoint snippets and connect an AI assistant through the MCP server.

App8 min

In this step you will learn how code, not a person, calls your model: with an API key, the REST endpoint and the MCP server. It matters because the value of a deployed model comes from the systems that use it, and those systems need a credential that is narrow, revocable and never shared.

The idea

A person signs in with a session; a script, a CI job or a service uses an API key. A key acts as you, with your roles, and a scope can make it do less. The scope predict (call deployed models) can call endpoints and batch jobs and nothing else, which is the right choice for any service that only consumes a model. Keys start with pck_, are shown once when created (only a hash is stored), can expire and can be revoked at any time.

mlflow offers three ways in: the web app (what you have used so far), the REST API and the MCP server, which lets an AI assistant such as Claude work with your workspace. The API and the MCP server both authenticate with an API key.

The card Use this endpoint on the Overview tab of a deployment shows the method, the URL, how to authenticate for the endpoint's access mode and snippets in curl, Python and JavaScript, built with your model's real feature columns.

Demo accounts cannot create API keys ("Demo accounts cannot create API keys. Create an account to use the API."). Read the steps in the demo; do them in a full account.

Step by step

  1. Open the user menu at the bottom of the sidebar (Account) and select API keys.
  2. Under New API key, enter a Name such as churn-scoring-service, optionally Expires in (days), and choose the scope predict (call deployed models). Leaving every scope unchecked gives default access (read, write and predict), so choose predict for a service that only scores.
  3. Select Create key. The card API key created — copy it now shows the key once. Copy it into your secret manager, then select I've saved it.
  4. In Your keys, check the Prefix, the status (active) and Last used. Select Revoke to disable a key you no longer need; this cannot be undone.
  5. Open your deployment, then Overview, then Use this endpoint. The card also offers Create API key with predict scope, which creates one and fills it into the snippets.
  6. Pick curl, Python or JavaScript and read the snippet. The key travels in the X-API-Key header and the body is {"rows": [{...}]}.
  7. To let an AI assistant use mlflow instead, give the MCP server a key (the predict scope is enough for scoring only) as described in the MCP server page of the documentation.
bash
# Plain HTTP: no library needed. Read the key from an environment variable.
curl -s -X POST "$ENDPOINT_URL" 
  -H "X-API-Key: $MLFLOW_API_KEY" 
  -H "Content-Type: application/json" 
  -d '{"rows": [{"tenure": 3, "plan": "basic"}]}'

What you should see

A key listed under Your keys as active with the predict scope, shown in full only once, and a snippet whose payload lists your model's feature columns.

Common mistakes

  • Pasting the key in code, a repository or a chat. If it leaks, revoke it and create another.
  • Giving a service a broad key. A wrong scope returns 403; a missing or invalid key returns 401.
  • Losing the key after closing the card. It cannot be shown again; create a new one.
  • Calling a workspace-mode endpoint from outside the app. Switch the deployment to API key mode in a full account.

As a data scientist

Create one key per consumer and name it after that consumer, so you can see in Last used who depends on the model and revoke one without breaking the rest. Set an expiry for keys that serve experiments. Treat the endpoint contract (column names and types) as an API: changing it breaks callers even when the model improves.

Checkpoint

You should see a key under Your keys with the status active and the predict scope (in a full account), and on the Overview tab a Use this endpoint card with code for curl, Python and JavaScript.

Theory to read next

Read in the docs