
Quick Answer
To get historical stock prices via API, call Valyu's POST https://api.valyu.ai/v1/search endpoint with a company name and date range in query. That is the only required request-body field. Authenticate with an API key, and Valyu returns structured price records with the resolved ticker, currency, exchange, and interval.
{"query": "Apple stock prices from January 2, 2024 to January 10, 2024"}
We tested this exact body against the production API. It returned seven daily Apple price records from valyu/valyu-stocks, covering the requested trading sessions. No ticker lookup, source filter, exchange parameter, or separate date fields were needed.
Why use Valyu for historical stock prices?
Historical prices are useful when building stock charts, company comparisons, research assistants, and financial dashboards. A human asks what a company traded at during a period; the application needs the underlying records.
Think of it as a Wayback machine for stocks: name the company and the period you want to inspect.
This is particularly suited to agents building tools for humans. An agent can take “Show me Apple's stock price in the first week of 2024” and pass the company name and dates directly in a search query. Valyu resolves the instrument and retrieves the history. The application can then turn the returned data into a chart, table, or comparison.
How to get historical stock prices with cURL
Get an API key from the Valyu platform, set it in your environment, and send the query:
export VALYU_API_KEY="your-api-key"curl --fail-with-body https://api.valyu.ai/v1/search \-H "Content-Type: application/json" \-H "X-API-Key: $VALYU_API_KEY" \-d '{"query": "Apple stock prices from January 2, 2024 to January 10, 2024"}'
The company and dates belong in the query. Your API key handles authentication. Market-data access depends on your account's dataset access; see the financial data guide.
How to get historical stock prices in Python
Install the SDK and set your API key:
pip install valyuexport VALYU_API_KEY="your-api-key"
Then call search() with one string:
from valyu import Valyuclient = Valyu()response = client.search("Apple stock prices from January 2, 2024 to January 10, 2024")if not response.success:raise RuntimeError("Historical price search failed")for result in response.results:if result.source == "valyu/valyu-stocks":print(result.metadata)print(result.content)
The SDK reads VALYU_API_KEY from the environment. The source check selects stock records from the response; it adds no parameters to the request. See the Python search reference.
How to get historical stock prices in TypeScript
Install the SDK and set your key:
pnpm add valyu-jsexport VALYU_API_KEY="your-api-key"
For a new Node.js TypeScript project, also install the compiler and Node.js types with pnpm add -D typescript @types/node.
import { Valyu } from "valyu-js";const client = new Valyu();const response = await client.search("Microsoft stock prices from January 2, 2024 to January 10, 2024",);if (!response.success) {throw new Error("Historical price search failed");}for (const result of response.results) {if (result.source === "valyu/valyu-stocks") {console.log(result.metadata);console.log(JSON.stringify(result.content, null, 2));}}
This is a useful retrieval step for a server-side app or agent tool. Keep the API key on the server. See the TypeScript SDK reference.
What does the historical stock price API return?
Our live Apple request returned an array of records in content, including open, high, low, close, and volume. Here is one actual record from that result:
{"datetime": "2024-01-10 00:00:00","open": 184.35001,"high": 186.39999,"low": 183.92,"close": 186.19,"volume": 46792900,"interval_end": "2024-01-10 23:59:59.999999"}
The accompanying metadata identified AAPL, Apple Inc., NASDAQ, USD, the America/New_York exchange timezone, and a 1day interval. The Microsoft query returned MSFT with the same date range and daily interval.
The tested SDK calls also returned native arrays of records. The observations arrived newest first, so sort them by datetime before plotting.
How to compare two stocks over the same date range
Run one query per company using the same dates. We tested Apple and Microsoft for 2-10 January 2024; both returned seven daily records.
| Company | 2 January close, USD | 10 January close, USD | Close-price change |
|---|---|---|---|
| Apple | 185.64 | 186.19 | +0.30% |
| Microsoft | 370.87 | 382.77 | +3.21% |
The displayed closes are rounded to two decimal places. The percentage changes use the original returned values and exclude dividends.
To compare the price paths on one chart, rebase each series with 100 * close / firstClose. Calculate the endpoint change with 100 * (lastClose / firstClose - 1). Do the arithmetic in application code or a calculation tool, using the returned records.
How to give an agent access to historical stock prices
Expose a tool with one argument, query, and connect it to client.search(query). Describe the tool as: “Retrieve historical stock prices. Include the company name and date range in the query.”
For a human asking to compare two companies, the agent makes one search per company. Your application checks the resolved instruments, aligns the trading sessions, and calculates or charts the result. The agent can then explain the comparison using those records.
For MCP-compatible agents, connect to Valyu's hosted server:
https://mcp.valyu.ai/mcp
Follow the MCP setup guide for authentication. The same company-and-date query can be passed to valyu_search; access follows the connected account.
What should you check before using the prices?
Company and listing. Check the returned ticker, name, exchange, and currency. If a company has multiple listings or share classes, describe the intended one in the query.
Dates and interval. Inspect the returned date coverage and interval. The tested daily series contains trading sessions, with no records for the weekend. Keep the exchange timezone with the data.
Price adjustments. The comparison above is a close-price change, excluding dividends. Check the adjustment basis before calculating returns across splits or using a series in a backtest.
Query dates. Put the historical period in query. The Search API's optional start_date and end_date fields are publication-date filters, not the date controls used in these stock-history examples. See the Search API reference.
FAQ
How do I get historical stock prices without a ticker?
Use a company name and date range in a Valyu search query. Our Apple and Microsoft tests returned the resolved tickers as output metadata without requiring them as input.
Do I need separate start-date and end-date parameters?
No. The tested REST requests contained only query, with the requested period in the string. An API key and access to the stock dataset are still required.
Can I get open, high, low, close, and volume?
Yes. The tested daily stock responses included all five fields, plus timestamps and instrument metadata.
Can an agent use this to build a stock chart?
Yes. The agent retrieves a company's price history with one query. The application sorts the observations and plots the returned prices for the human using the product.
Which Valyu source contains stock prices?
Historical stock prices are available through valyu/valyu-stocks. The demonstrated query-only requests routed to it automatically. See the data coverage page.
If you're an agent: Set up Valyu and ask for a company and date range.
If you're a human: Get an API key and run the example above.
More from the blog





Valyu Add
Join 12,000+ professionals and knowledge workers.
Valyu Add is a free weekly research briefing for builders, investors and operators. Every issue is sourced, cited and verified with Valyu DeepResearch.
