Everything you need before your first request. Get an API key and make a call in five steps, see how authentication, parameters, and responses work, look up error codes, and pick an official SDK, AI integration, or spreadsheet add-on.
To get started, you'll need to sign up for an API key. Once you have your API key, you can start making requests to the API.
Sign up on the Twelve Data website to create your account here. This gives you access to the API dashboard and your API key.
After signing in, navigate to your dashboard to find your unique API key. This key is required to authenticate all API and WebSocket requests.
Try a simple API call with cURL to fetch the latest price for Apple (AAPL):
curl "https://api.twelvedata.com/price?symbol=AAPL&apikey=your_api_key"
Use our client libraries or standard HTTP clients to make API calls programmatically. Here’s an example in Python and Node.js:
from twelvedata import TDClient
# Initialize client with your API key
td = TDClient(apikey="your_api_key")
# Get latest price for Apple
price = td.price(symbol="AAPL").as_json()
print(price)
import { MarketDataApi, CreateConfig } from "@twelvedata/twelvedata-node";
const config = CreateConfig('your_api_key');
const api = new MarketDataApi(config);
async function main() {
const response = await api.getPrice({
symbol: "AAPL",
});
console.log(response.data);
}
main().catch(console.error);
Fetch historical price data for Tesla (TSLA) and Microsoft (MSFT) and calculate the correlation of their closing prices:
from twelvedata import TDClient
import pandas as pd
# Initialize client with your API key
td = TDClient(apikey="your_api_key")
# Fetch historical price data for Tesla
tsla_ts = td.time_series(
symbol="TSLA",
interval="1day",
outputsize=100
).as_pandas()
# Fetch historical price data for Microsoft
msft_ts = td.time_series(
symbol="MSFT",
interval="1day",
outputsize=100
).as_pandas()
# Align data on datetime index
combined = pd.concat(
[tsla_ts['close'].astype(float), msft_ts['close'].astype(float)],
axis=1,
keys=["TSLA", "MSFT"]
).dropna()
# Calculate correlation
correlation = combined["TSLA"].corr(combined["MSFT"])
print(f"Correlation of closing prices between TSLA and MSFT: {correlation:.2f}")
Authenticate your requests using one of these methods:
GET https://api.twelvedata.com/endpoint?symbol=AAPL&apikey=your_api_key
Authorization: apikey your_api_key
apikey=demo) available for demo requests| Service | Base URL |
|---|---|
| REST API | https://api.twelvedata.com |
| WebSocket | wss://ws.twelvedata.com |
& to separate multiple parameterssymbol=AAPL = symbol=aapl)All responses return JSON format by default unless otherwise specified.
Important: Some response fields may contain null values when data is unavailable for specific metrics. This is expected behavior, not an error.
null value handling in your applicationStructure your code to gracefully handle:
429 Too Many Requests).Twelve Data API employs a standardized error response format, delivering a JSON object with code, message, and status keys for clear and consistent error communication.
Below is a table of possible error codes, their HTTP status, meanings, and resolution steps:
| Code | status | Meaning | Resolution |
|---|---|---|---|
| 400 | Bad Request | Invalid or incorrect parameter(s) provided. | Check the message in the response for details. Refer to the API Documentation to correct the input. |
| 401 | Unauthorized | Invalid or incorrect API key. | Verify your API key is correct. Sign up for a key here. |
| 403 | Forbidden | API key lacks permissions for the requested resource (upgrade required). | Upgrade your plan here. |
| 404 | Not Found | Requested data could not be found. | Adjust parameters to be less strict as they may be too restrictive. |
| 414 | Parameter Too Long | Input parameter array exceeds the allowed length. | Follow the message guidance to adjust the parameter length. |
| 429 | Too Many Requests | API request limit reached for your key. | Wait briefly or upgrade your plan here. |
| 500 | Internal Server Error | Server-side issue occurred; retry later. | Contact support here for assistance. |
Consider the following invalid request:
https://api.twelvedata.com/time_series?symbol=AAPL&interval=0.99min&apikey=your_api_key
Due to the incorrect interval value, the API returns:
{
"code": 400,
"message": "Invalid **interval** provided: 0.99min. Supported intervals: 1min, 5min, 15min, 30min, 45min, 1h, 2h, 4h, 8h, 1day, 1week, 1month",
"status": "error"
}
Refer to the API Documentation for valid parameter values to resolve such errors.
Twelve Data provides a growing ecosystem of libraries and integrations to help you build faster and smarter in your preferred environment. Official libraries are actively maintained by the Twelve Data team, while selected community-built libraries offer additional flexibility.
A full list is available on our GitHub profile.
The community has developed libraries in several popular languages. You can explore more community libraries on GitHub.