curl --request POST \
--url https://api.valyu.ai/v1/answer \
--header 'Content-Type: application/json' \
--header 'X-API-Key: <api-key>' \
--data '
{
"query": "What are the latest FDA-approved treatments for type 2 diabetes?"
}
'Answer
Deprecated. POST /v1/answer sunsets on December 17, 2026. Migrate to DeepResearch instant mode or to Search with your own model.
curl --request POST \
--url https://api.valyu.ai/v1/answer \
--header 'Content-Type: application/json' \
--header 'X-API-Key: <api-key>' \
--data '
{
"query": "What are the latest FDA-approved treatments for type 2 diabetes?"
}
'POST /v1/answer returns HTTP 410 Gone. Until then it keeps working. Move to DeepResearch instant mode or to Search with your own model.Consume the stream
The HTTP endpoint returns server-sent events, not one JSON response. Handlesearch_results, content and metadata events, followed by [DONE]. If the answer fails mid-stream, you receive {"error": "Streaming failed"} and the stream ends, even though the HTTP status was 200. Keep the returned sources with the answer. The metadata event also carries any warnings from the searches the answer ran.
There is no per-request fee. Each answer is charged for the search, content extraction and AI processing it uses, and cost.total_deduction_dollars in the final metadata event is the amount billed.
Source and date controls narrow retrieval. They do not guarantee that every claim is supported or that all relevant evidence was found. For a longer asynchronous investigation with a report and optional files, use DeepResearch.
Migrate from Answer
Answer calls that you do not move by December 17, 2026 fail with HTTP410. Responses from POST /v1/answer before that date carry these headers:
| Header | Value |
|---|---|
Deprecation | Marks the endpoint as deprecated. |
Sunset | Thu, 17 Dec 2026 00:00:00 GMT |
Link header points to this section. Valyu SDK answer() methods log a deprecation warning from valyu-py 2.13.8 and valyu-js 2.11.8.
Pick the replacement that fits how you use Answer.
| You use Answer to | Move to |
|---|---|
| Get a short cited answer to a focused question | DeepResearch with mode: "instant" |
| Control the model, prompt and streaming yourself | Search plus your own LLM |
DeepResearch instant mode
instant mode returns a short cited answer in under 30 seconds and uses 8 credits per task. You create a task, then read its status until it completes. It is not a server-sent event stream. The result has the answer in output (markdown with numbered citations) and the sources in sources.
| Answer | DeepResearch |
|---|---|
query | query |
search_type, included_sources, excluded_sources, country_code, start_date, end_date | Same names inside the search object |
data_max_price, fast_mode, structured_output | No direct match. Use mode to set depth and cost, and output_formats for structured output. |
system_instructions | report_format |
curl https://api.valyu.ai/v1/deepresearch/tasks \
-H "x-api-key: $VALYU_API_KEY" \
-H "Content-Type: application/json" \
-d '{"query": "How do public companies describe supply chain concentration risks?", "mode": "instant"}'
# Save deepresearch_id from the response, then poll until status is completed.
curl https://api.valyu.ai/v1/deepresearch/tasks/$DEEPRESEARCH_ID/status \
-H "x-api-key: $VALYU_API_KEY"
from valyu import Valyu
valyu = Valyu()
task = valyu.deepresearch.create(
query="How do public companies describe supply chain concentration risks?",
mode="instant",
)
if not task.success:
raise RuntimeError(task.error)
result = valyu.deepresearch.wait(task.deepresearch_id)
if result.status == "completed":
print(result.output)
for source in result.sources or []:
print(source.title, "-", source.url)
import { Valyu } from "valyu-js";
const valyu = new Valyu();
const task = await valyu.deepresearch.create({
query: "How do public companies describe supply chain concentration risks?",
mode: "instant",
});
if (!task.success || !task.deepresearch_id) throw new Error(task.error);
const result = await valyu.deepresearch.wait(task.deepresearch_id);
if (result.status === "completed") {
console.log(result.output);
for (const source of result.sources ?? []) console.log(source.title, "-", source.url);
}
status before you read output. For longer research, pick another mode.
Search plus your own LLM
Use Search to get ranked results withtitle, url and content, then pass them to your own model. Keep the url with each passage so the answer can cite it.
from valyu import Valyu
valyu = Valyu()
response = valyu.search("How do public companies describe supply chain concentration risks?", max_num_results=8)
if not response.success:
raise RuntimeError(response.error)
context = "\n\n".join(f"[{i + 1}] {r.title} ({r.url})\n{r.content}" for i, r in enumerate(response.results))
prompt = f"Answer the question using only the numbered sources and cite them as [n].\n\n{context}"
# Send `prompt` to your own model.
import { Valyu } from "valyu-js";
const valyu = new Valyu();
const response = await valyu.search(
"How do public companies describe supply chain concentration risks?",
{ maxNumResults: 8 }
);
if (!response.success) throw new Error(response.error);
const context = response.results
.map((r, i) => `[${i + 1}] ${r.title} (${r.url})\n${typeof r.content === "string" ? r.content : JSON.stringify(r.content)}`)
.join("\n\n");
const prompt = `Answer the question using only the numbered sources and cite them as [n].\n\n${context}`;
// Send `prompt` to your own model.
Authorizations
API key for authentication. Get yours at platform.valyu.ai.
Body
Answer API request parameters.
JSON Schema defining the desired output structure. When set, the AI returns a JSON object matching this schema instead of free-form text. Max depth 10, max 50 properties, max 5000 characters.
{
"type": "object",
"properties": {
"treatments": {
"type": "array",
"items": {
"type": "object",
"properties": {
"name": { "type": "string" },
"approval_date": { "type": "string" },
"mechanism": { "type": "string" }
}
}
}
}
}
Response
SSE stream of search results, answer chunks, and metadata.
Server-Sent Events stream. Each event has format: data: {json}\n\n
search_results event:
{"search_results": [{"title": "...", "url": "...", "content": "...", ...}]}
content event (OpenAI-compatible):
{"choices": [{"delta": {"role": "assistant", "content": "text chunk"}, "index": 0}]}
metadata event:
{"success": true, "tx_id": "ai_tx_...", "original_query": "...", "contents": "Full answer text...", "search_results": [{"title": "...", "url": "...", "content": "...", "description": "...", "source": "web", "source_type": "website", "data_type": "unstructured", "date": "...", "length": 1200, "image_url": {}}], "search_metadata": {"tx_ids": ["tx_..."], "number_of_results": 10, "total_characters": 50000}, "ai_usage": {"input_tokens": 15000, "output_tokens": 2000}, "cost": {"total_deduction_dollars": 0.0475, "search_deduction_dollars": 0.00625, "ai_deduction_dollars": 0.03625, "contents_deduction_dollars": 0.005}}
contents is the full answer (JSON text when structured_output is set). total_deduction_dollars is the amount billed. When the searches behind the answer skipped or adjusted something, the metadata event also carries warnings: the warnings of those searches, deduplicated, in the same {type, message, detail} shape as Search. See Warnings.
error event:
{"error": "Streaming failed"}
done signal:
data: [DONE]
Was this page helpful?