Skip to main content

Your First Request

This guide walks you through making your first Cortex API request, understanding parameters, and interpreting responses.

🎯 Basic Search Request

Let's start with a simple search:

curl -X POST https://api.usecortex.co/v1/search \
-H "Authorization: Bearer YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"query": "latest developments in quantum computing"
}'

📝 Request Structure

Required Parameters

ParameterTypeDescription
querystringYour search query (max 500 characters)

Optional Parameters

ParameterTypeDefaultDescription
max_resultsinteger5Number of sources to analyze (1-20)
include_sourcesbooleantrueInclude source citations
languagestring"auto"Target language (en, es, fr, de, etc.)
recencystring"auto"Filter by recency (day, week, month, year)
domain_filterarraynullInclude/exclude specific domains
countrystring"global"Geographic focus (us, uk, de, etc.)

🔍 Advanced Request Examples

News Search with Recency Filter

{
"query": "Tesla stock price movement",
"max_results": 8,
"recency": "day",
"domain_filter": {
"include": ["reuters.com", "bloomberg.com", "cnbc.com"]
}
}

Research Query with Language Preference

{
"query": "machine learning breakthrough 2025",
"max_results": 10,
"language": "en",
"domain_filter": {
"include": ["arxiv.org", "nature.com", "science.org"],
"exclude": ["wikipedia.org"]
}
}
{
"query": "renewable energy policies",
"country": "de",
"language": "en",
"max_results": 6
}

📊 Response Structure

Here's a detailed breakdown of the response:

{
"summary": "Quantum computing has seen significant advances...",
"sources": [
{
"url": "https://example.com/quantum-breakthrough",
"title": "Major Quantum Computing Breakthrough Announced",
"snippet": "Scientists at MIT have developed...",
"confidence": 0.94,
"published_date": "2025-01-08T15:30:00Z",
"domain": "example.com",
"language": "en",
"word_count": 1200
}
],
"metadata": {
"query_time": 2.15,
"sources_found": 47,
"sources_analyzed": 8,
"confidence_score": 0.91,
"cached": false,
"model_version": "cortex-v2.1"
},
"query_analysis": {
"intent": "research",
"entities": ["quantum computing", "developments"],
"complexity": "medium"
},
"request_id": "req_8f3a2b1c9d4e5f67"
}

Response Fields Explained

Summary

  • Type: String
  • Description: AI-generated summary combining information from all sources
  • Length: Typically 150-500 words
  • Language: Matches request language preference

Sources Array

Each source object contains:

FieldTypeDescription
urlstringOriginal source URL
titlestringPage title
snippetstringRelevant excerpt (150-300 chars)
confidencefloatRelevance confidence (0.0-1.0)
published_datestringPublication date (ISO 8601)
domainstringSource domain
languagestringContent language
word_countintegerApproximate article length

Metadata Object

Performance and quality metrics:

FieldDescription
query_timeTotal processing time (seconds)
sources_foundTotal sources discovered
sources_analyzedSources used for summary
confidence_scoreOverall response confidence
cachedWhether result was cached
model_versionAI model version used

🎨 Response Formats

Markdown Format

Request markdown-formatted responses:

{
"query": "Python data science libraries",
"format": "markdown",
"include_citations": true
}

Response:

# Python Data Science Libraries

The Python ecosystem offers several powerful libraries for data science:

## Core Libraries
- **NumPy** - Fundamental package for numerical computing[^1]
- **Pandas** - Data manipulation and analysis[^2]
- **Matplotlib** - Comprehensive plotting library[^3]

[^1]: https://numpy.org/doc/stable/
[^2]: https://pandas.pydata.org/docs/
[^3]: https://matplotlib.org/stable/contents.html

Structured Data

For programmatic use:

{
"query": "compare iPhone vs Samsung Galaxy specs",
"format": "structured",
"schema": "comparison"
}

⚡ Performance Optimization

Caching

Cortex automatically caches frequent queries:

{
"query": "daily weather forecast New York",
"cache_ttl": 3600 // Cache for 1 hour
}

Streaming Responses

For real-time applications:

curl -X POST https://api.usecortex.co/v1/search \
-H "Authorization: Bearer YOUR_API_KEY" \
-H "Accept: text/event-stream" \
-d '{"query": "breaking news", "stream": true}'

🚨 Error Handling

Common Errors

Status CodeErrorDescription
400Bad RequestInvalid query parameters
401UnauthorizedInvalid API key
429Rate LimitedToo many requests
500Server ErrorInternal processing error

Error Response Format

{
"error": {
"code": "INVALID_QUERY",
"message": "Query parameter is required",
"details": {
"parameter": "query",
"provided": null,
"expected": "string (1-500 characters)"
}
},
"request_id": "req_error_123"
}

Retry Logic

Implement exponential backoff:

import time
import requests
from requests.adapters import HTTPAdapter
from urllib3.util.retry import Retry

def make_request_with_retry(query):
session = requests.Session()

retry_strategy = Retry(
total=3,
backoff_factor=1,
status_forcelist=[429, 500, 502, 503, 504],
)

adapter = HTTPAdapter(max_retries=retry_strategy)
session.mount("https://", adapter)

response = session.post(
"https://api.usecortex.co/v1/search",
headers={"Authorization": "Bearer YOUR_API_KEY"},
json={"query": query}
)

return response.json()

📈 Testing Your Integration

Health Check

curl -H "Authorization: Bearer YOUR_API_KEY" \
https://api.usecortex.co/v1/health

Rate Limit Check

curl -I -H "Authorization: Bearer YOUR_API_KEY" \
https://api.usecortex.co/v1/search

Response headers include:

X-RateLimit-Limit: 100
X-RateLimit-Remaining: 95
X-RateLimit-Reset: 1640995200

💡 Best Practices

Query Optimization

✅ Good queries:

  • "latest iPhone 15 reviews and specifications"
  • "renewable energy investment trends 2025"
  • "machine learning papers published this month"

❌ Avoid:

  • Single words: "AI"
  • Too broad: "everything about technology"
  • Too specific: "John Smith from 123 Main St opinions"

Efficient Usage

  1. Cache results for repeated queries
  2. Use appropriate max_results (5-10 for most cases)
  3. Filter domains for specific use cases
  4. Set reasonable timeouts (5-10 seconds)

🔄 Next Steps

Now that you've made your first request:

🆘 Troubleshooting

Slow responses?

  • Reduce max_results
  • Use domain filtering
  • Check your internet connection

Low quality results?

  • Make queries more specific
  • Use domain filtering for authoritative sources
  • Try different query phrasings

Need help?


Next: API Overview → - Deep dive into all available endpoints