Research API
Generate comprehensive research reports using GPT-Researcher and web search
16 Oct 2025 - Current Implementation
Overview
The Research API provides AI-powered research report generation using GPT-Researcher. Generate comprehensive, well-sourced research reports on stocks with:
- Web Search Integration - Automatically searches and synthesizes information from the web
- Predefined Templates - Deep dive, industry analysis, risk assessment, growth opportunities
- Custom Queries - Ask any research question about a stock
- Source Citations - All reports include full source URLs
- Markdown Output - Professional, well-formatted reports saved to snapshot folders
- OpenAI API Key - Required for GPT-4 based research (configure in Settings API)
- Tavily API Key - Required for web search capabilities (configure in Settings API)
- Stock Snapshot - Research reports are associated with specific snapshots
- Processing Time - Reports typically take 60-120 seconds to generate
Research Templates
QuantCoderFS provides four predefined research templates optimized for equity research:
| Template | Value | Focus | Use Case |
|---|---|---|---|
| Deep Dive | deep_dive |
Comprehensive analysis of company, products, competitive position | New stock research, initial due diligence |
| Industry Analysis | industry |
Sector trends, competitive landscape, market dynamics | Understanding industry context |
| Risk Assessment | risk |
Business risks, regulatory concerns, competitive threats | Risk management, downside analysis |
| Growth Opportunities | growth |
Expansion plans, new markets, product pipeline | Identifying catalysts, upside potential |
Core Endpoints
Generate a comprehensive research report using GPT-Researcher.
Path Parameters
-
ticker string requiredStock ticker symbol (e.g., "AAPL.US")
-
snapshot_id string requiredSnapshot ID (format: YYYYMMDD_HHMMSS)
Request Body
{
"query": "Provide a comprehensive analysis of Apple Inc.",
"template": "deep_dive"
}
Request Parameters
| Field | Type | Required | Description |
|---|---|---|---|
query |
string | Yes | Research question or topic to investigate |
template |
string | No | Predefined template: "deep_dive", "industry", "risk", or "growth" (null for custom query) |
Example Request - Template (cURL)
curl -X POST \
"http://localhost:8004/api/stocks/AAPL.US/snapshots/20251016_143022/research/generate" \
-H "Content-Type: application/json" \
-d '{
"query": "Provide a comprehensive analysis of Apple Inc.",
"template": "deep_dive"
}'
Example Request - Custom Query (Python)
import requests
response = requests.post(
"http://localhost:8004/api/stocks/AAPL.US/snapshots/20251016_143022/research/generate",
json={
"query": "What are Apple's competitive advantages in the smartphone market?",
"template": null # Custom query, no template
}
)
research = response.json()
print(f"Report saved to: {research['saved_path']}")
print(f"Sources: {len(research['sources'])}")
print(research['report'][:500]) # Print first 500 chars
Processing Flow
This endpoint performs the following research steps:
- Validates API keys (OpenAI and Tavily) from Settings
- Initializes GPT-Researcher with ticker and API keys
- If template specified: Uses predefined research query and methodology
- If custom query: Researches the exact question provided
- Searches the web using Tavily API (10-20 sources)
- Synthesizes findings using GPT-4
- Generates structured Markdown report with sources
- Saves report to
/stocks/{ticker}/{snapshot_id}/research/ - Returns report content and metadata
Typical execution time: 60-120 seconds
Response (200 OK)
{
"query": "Provide a comprehensive analysis of Apple Inc.",
"report": "# Apple Inc. - Comprehensive Analysis\n\n## Executive Summary\n\nApple Inc. (NASDAQ: AAPL) is the world's largest technology company...\n\n## Company Overview\n\nFounded in 1976, Apple has evolved from a personal computer manufacturer...\n\n## Products and Services\n\n### iPhone\nThe iPhone represents approximately 52% of total revenue...\n\n### Services\nApple's services segment has grown to $85B annually...\n\n## Competitive Position\n\nApple maintains strong competitive moats through...\n\n## Financial Performance\n\nRevenue: $394B (FY2023)\nGross Margin: 44%\nNet Income: $97B\n\n## Outlook\n\nKey growth drivers include...\n\n## Conclusion\n\nApple demonstrates exceptional fundamentals...",
"sources": [
"https://www.apple.com/investor/",
"https://www.sec.gov/cgi-bin/browse-edgar?action=getcompany&CIK=0000320193",
"https://www.bloomberg.com/quote/AAPL:US",
"https://www.cnbc.com/apple/",
"https://9to5mac.com/guides/iphone/",
"https://www.macrumors.com/",
"https://www.statista.com/statistics/apple/",
"https://www.marketwatch.com/investing/stock/aapl"
],
"report_type": "deep_dive",
"ticker": "AAPL.US",
"saved_path": "/home/user/stocks/AAPL.US/20251016_143022/research/research_deep_dive_20251016_153045.md"
}
Response Fields
| Field | Type | Description |
|---|---|---|
query |
string | The research query that was executed |
report |
string | Full markdown report content |
sources |
array | List of source URLs used in the research |
report_type |
string | Template used ("deep_dive", "industry", "risk", "growth", or "custom") |
ticker |
string | Stock ticker symbol |
saved_path |
string | Absolute path where report was saved |
Error Responses
| Status Code | Description |
|---|---|
| 400 | OpenAI and Tavily API keys must be configured in Settings |
| 404 | Stock snapshot not found |
| 500 | Error generating research report (API error, timeout, etc.) |
Research File Management
List all research report files for a specific snapshot.
Path Parameters
-
ticker string requiredStock ticker symbol
-
snapshot_id string requiredSnapshot ID (format: YYYYMMDD_HHMMSS)
Example Request
curl "http://localhost:8004/api/stocks/AAPL.US/snapshots/20251016_143022/research/files"
Response (200 OK)
[
{
"filename": "research_deep_dive_20251016_153045.md",
"path": "/home/user/stocks/AAPL.US/20251016_143022/research/research_deep_dive_20251016_153045.md",
"size_kb": 52.3,
"modified": 1729089045.234
},
{
"filename": "research_risk_20251016_145022.md",
"path": "/home/user/stocks/AAPL.US/20251016_143022/research/research_risk_20251016_145022.md",
"size_kb": 38.7,
"modified": 1729087822.156
},
{
"filename": "research_custom_20251016_140512.md",
"path": "/home/user/stocks/AAPL.US/20251016_143022/research/research_custom_20251016_140512.md",
"size_kb": 28.1,
"modified": 1729086312.789
}
]
Response Fields
| Field | Type | Description |
|---|---|---|
filename |
string | Report filename (format: research_{template}_{timestamp}.md) |
path |
string | Absolute file path |
size_kb |
float | File size in kilobytes |
modified |
float | Unix timestamp of last modification |
Note: Results are sorted by modified date (newest first).
Get the content of a specific research report.
Path Parameters
-
ticker string requiredStock ticker symbol
-
snapshot_id string requiredSnapshot ID
-
filename string requiredResearch report filename (must start with "research_" and end with ".md")
Example Request
curl "http://localhost:8004/api/stocks/AAPL.US/snapshots/20251016_143022/research/content/research_deep_dive_20251016_153045.md"
Response (200 OK)
{
"filename": "research_deep_dive_20251016_153045.md",
"content": "# Research Report: Provide a comprehensive analysis of Apple Inc.\n\n**Ticker:** AAPL.US\n\n**Report Type:** deep_dive\n\n---\n\n# Apple Inc. - Comprehensive Analysis\n\n## Executive Summary\n\nApple Inc. (NASDAQ: AAPL) is the world's largest technology company...\n\n[Full markdown content here]\n\n---\n\n## Sources\n\n1. https://www.apple.com/investor/\n2. https://www.sec.gov/cgi-bin/browse-edgar?action=getcompany&CIK=0000320193\n3. https://www.bloomberg.com/quote/AAPL:US\n..."
}
Security Validation
This endpoint validates filenames to prevent directory traversal attacks:
- Must start with
research_ - Must end with
.md - Cannot contain
/or..
Error Responses
| Status Code | Description |
|---|---|
| 400 | Invalid filename (security validation failed) |
| 404 | Research file not found |
Delete a specific research report file from a snapshot.
Path Parameters
-
ticker string requiredStock ticker symbol
-
snapshot_id string requiredSnapshot ID
-
filename string requiredResearch report filename to delete
Example Request
curl -X DELETE \
"http://localhost:8004/api/stocks/AAPL.US/snapshots/20251016_143022/research/research_custom_20251016_140512.md"
Response (200 OK)
{
"message": "Research file deleted successfully",
"filename": "research_custom_20251016_140512.md"
}
Error Responses
| Status Code | Description |
|---|---|
| 400 | Invalid filename |
| 404 | Research file not found |
| 500 | Failed to delete file |
Report Structure
All research reports are saved as Markdown files with the following structure:
Example Report Structure
# Research Report: [Query]
**Ticker:** AAPL.US
**Report Type:** deep_dive
---
# [Report Title]
## Executive Summary
[High-level overview of findings]
## Section 1
[Detailed analysis...]
## Section 2
[Detailed analysis...]
## Conclusion
[Summary and recommendations]
---
## Sources
1. https://source1.com
2. https://source2.com
3. https://source3.com
...
File Naming Convention
Research report filenames follow a consistent pattern:
| Pattern | Example | Description |
|---|---|---|
research_{template}_{timestamp}.md |
research_deep_dive_20251016_153045.md |
Template-based report |
research_custom_{timestamp}.md |
research_custom_20251016_140512.md |
Custom query report |
GPT-Researcher Integration
QuantCoderFS uses GPT-Researcher, an autonomous research agent that:
- Plans - Generates a research plan based on the query
- Searches - Uses Tavily API to find relevant web sources
- Scrapes - Extracts content from source pages
- Filters - Identifies most relevant information
- Synthesizes - Uses GPT-4 to write comprehensive reports
- Cites - Includes full source URLs for verification
Benefits: More comprehensive than simple web search, well-structured outputs, proper source attribution
Best Practices
- Specific Queries - More specific questions yield better, more focused reports
- Template Selection - Use templates for standard research needs, custom queries for specific questions
- Multiple Reports - Generate multiple reports (e.g., deep_dive + risk) for comprehensive coverage
- Source Verification - Always review source URLs to assess report quality and bias
- Timing - Reports take 1-2 minutes; consider implementing async generation for production
- API Costs - Each report uses GPT-4 and web search credits; monitor API usage
- Research reports are for informational purposes only, not investment advice
- Web sources may contain outdated or inaccurate information
- GPT-4 can occasionally hallucinate facts; verify important claims
- Tavily API free tier has rate limits (1000 requests/month)
- Reports are stored locally and not backed up automatically
Error Responses
| Status Code | Description |
|---|---|
| 400 | Invalid request (missing API keys, invalid filename) |
| 404 | Stock snapshot or research file not found |
| 500 | Error generating research (API timeout, service unavailable) |
Next Steps
- Stocks API - Create stock snapshots for research
- Signals API - Generate trading signals based on research
- Settings API - Configure OpenAI and Tavily API keys
- Dependencies & Third-Party Services