# Twelve Data auth.md — Authentication

The REST API uses API key authentication. The hosted MCP server uses OAuth 2.1 (see below).

## Getting an API key

1. Register at https://twelvedata.com/register — the Basic plan is free and requires no credit card.
2. Your API key is shown in the dashboard: https://twelvedata.com/account/api-keys

## Using the API key

The REST API base URL is `https://api.twelvedata.com`. Pass the key in one of two ways:

As a query parameter:

```
GET https://api.twelvedata.com/price?symbol=AAPL&apikey=your_api_key
```

Or as a header:

```
Authorization: apikey your_api_key
```

The WebSocket endpoint `wss://ws.twelvedata.com` uses the same API key. The hosted MCP server does not accept API keys; it uses OAuth (see below).

## MCP server (OAuth)

The hosted MCP server at `https://mcp.twelvedata.com/mcp` uses OAuth 2.1 with the
authorization server at `https://auth.twelvedata.com`. MCP clients (Claude,
ChatGPT, etc.) authorize interactively — authorization code flow with PKCE
(`S256`), refresh tokens, client ID metadata documents and dynamic client
registration (RFC 7591) are supported. Send the access token as
`Authorization: Bearer <token>`.

- Authorization server metadata (RFC 8414): https://auth.twelvedata.com/.well-known/oauth-authorization-server
- Protected resource metadata (RFC 9728): https://mcp.twelvedata.com/.well-known/oauth-protected-resource/mcp

OAuth applies to the MCP server only; the REST API at `https://api.twelvedata.com`
uses API keys.

## Client registration

Before authorizing, a client needs a `client_id`. Client ID Metadata Documents
are the recommended way to get one; Dynamic Client Registration is deprecated by
the MCP specification and kept for backwards compatibility and for clients that
cannot host a document. See
https://modelcontextprotocol.io/specification/2026-07-28/basic/authorization/client-registration

### Client ID Metadata Documents (recommended)

The `client_id` is an HTTPS URL, with a path, that serves the client's metadata
as JSON. The authorization server fetches it during authorization, and the
consent screen names the client together with that URL's domain. No registration
request is made.

```
GET https://agent.example.com/oauth/client-metadata.json

{
  "client_id": "https://agent.example.com/oauth/client-metadata.json",
  "client_name": "my-agent",
  "redirect_uris": ["https://agent.example.com/callback"],
  "grant_types": ["authorization_code", "refresh_token"],
  "token_endpoint_auth_method": "none"
}
```

The document's `client_id` must equal its URL exactly. `client_name` and
`redirect_uris` are required, and `token_endpoint_auth_method` is `none` (the
default) or `private_key_jwt` with a `jwks_uri`.

### Dynamic Client Registration (deprecated)

Agents without a domain of their own can self-register an OAuth client without
human involvement via Dynamic Client Registration (RFC 7591):

```
POST https://auth.twelvedata.com/register
Content-Type: application/json

{
  "client_name": "my-agent",
  "redirect_uris": ["https://agent.example.com/callback"],
  "grant_types": ["authorization_code", "refresh_token"],
  "token_endpoint_auth_method": "none"
}
```

Registered clients are public: the response contains a `client_id` and no
`client_secret`, whatever `token_endpoint_auth_method` was requested.
Registration is anonymous — no account is required to obtain a client — and the
consent screen says that the client's name has not been verified.

### Authorization

With either kind of `client_id`, run the standard authorization code flow with
PKCE against the endpoints listed in
https://auth.twelvedata.com/.well-known/oauth-authorization-server
(`authorization_endpoint`, `token_endpoint`; scope: `twelvedata`). The
authorization and token requests carry `resource=https://mcp.twelvedata.com/mcp`
(RFC 8707); an authorization request without it is refused. Tokens can be
revoked at the `revocation_endpoint`.

The user signs in with a Twelve Data account during authorization; to create one
(and manage API keys, plans, and limits), register at https://twelvedata.com/register.

## Errors and limits

- `401` — missing or invalid API key.
- `429` — rate limit exceeded; request frequency and credit limits depend on the plan (see https://twelvedata.com/pricing).
- Most endpoints cost 1 API credit per symbol; premium data (fundamentals, analysis) costs more.

## More information

- Documentation: https://twelvedata.com/docs
- Documentation for LLMs: https://twelvedata.com/docs/llms.txt
- OpenAPI specification: https://api.twelvedata.com/doc/swagger/openapi.json
- API catalog: https://twelvedata.com/.well-known/api-catalog
