Skip to main content
Use an API key from mtaapi.dev to authenticate requests to the hosted MTA API. You can send the key directly with REST or MCP, or pass it to the mta-js client.
Never hardcode your API key directly in source code. If you commit a key to a public repository, anyone can use it to make requests on your behalf. Always load keys from environment variables.

Get an API key

  1. Sign in at mtaapi.dev.
  2. Choose a paid plan from the Billing tab. API keys require an active paid plan.
  3. Open API keys and create a key.
The key secret is shown only once. Copy it and store it securely before closing the dialog. If you do not have a plan, key creation returns a message asking you to choose one first.
Prefer to self-host and call MTA feeds directly? See Direct MTA feeds on the Quick Start page. The rest of this page assumes you’re using the hosted mtaapi.dev API.

Manage keys from an agent

MCP account tools can create, list, and revoke your API keys after you sign in with Clerk OAuth. The tools are create_api_key, list_api_keys, and revoke_api_key. See MCP server for connection and authentication instructions.

Store your key safely

Add your key to a .env file at the root of your project:
.env
Make sure .env is listed in your .gitignore:
.gitignore
Most JavaScript frameworks (Next.js, Remix, Astro) and runtimes load .env files automatically. For plain Node.js projects, install dotenv and call require('dotenv').config() at the top of your entry file, or use the --env-file flag available in Node.js 20+.

Send your key

mta-js

Pass your API key to the MTA constructor as apiKey. The SDK routes requests to https://www.mtaapi.dev/api/v1 automatically and sends both x-api-key and Authorization: Bearer <key> headers for you.
Create one client instance and reuse it across your application. In a serverless environment (Vercel Functions, Cloudflare Workers, AWS Lambda), initialize the client inside the request handler so environment variables are available at invocation time:

REST API

Protected endpoints accept either x-api-key: <key> or Authorization: Bearer <key>. The mta-js client sends both headers automatically. REST requests use the https://www.mtaapi.dev/api/v1 base URL. MCP clients must use Authorization: Bearer <key>; the x-api-key header is not accepted by the MCP endpoint.

MCP server

The MCP endpoint is https://www.mtaapi.dev/mcp. It requires Authorization: Bearer <key>; the x-api-key header is not accepted by this endpoint. See MCP server for client configuration.

Rotate or revoke a key

To rotate a key without interrupting requests:
  1. Create a new key in the dashboard.
  2. Deploy the new secret to every environment that uses it.
  3. Confirm requests succeed with the new key, then revoke the old key from the dashboard.
Revoking a key makes it stop working for subsequent requests. Update any clients still using it before revocation.

Authentication and quota errors

The API returns the following status codes and messages: Check that MTA_API_KEY is set without printing the secret. If you rotated a key, update it in every environment where it is used before revoking the previous key.