Authentication
All API requests require authentication using an API key. Include your API key in the Authorization header:
Authorization: Bearer YOUR_API_KEY
Get your API key at app.trynia.ai.
Store your API key in an environment variable or secret manager. Rotate it immediately if compromised.
Base URL
All API endpoints are available at:
https://apigcp.trynia.ai/v2
Rate Limits
View your current usage and limits at app.trynia.ai. See the Pricing page for plan details.
When you exceed rate limits, the API returns a 429 status code:
{
"error": "Rate limit exceeded",
"status": 429
}
Rate limit headers are included in responses:
| Header | Description |
|---|
X-RateLimit-Limit | Rate limit ceiling for the endpoint |
X-RateLimit-Remaining | Remaining requests in current window |
X-RateLimit-Reset | Time when the rate limit resets |
X-Monthly-Limit | Monthly request limit |
Quick Start Examples
Index a Repository
curl -X POST https://apigcp.trynia.ai/v2/repositories \
-H "Authorization: Bearer $NIA_API_KEY" \
-H "Content-Type: application/json" \
-d '{"repository": "vercel/ai"}'
Index Documentation
curl -X POST https://apigcp.trynia.ai/v2/data-sources \
-H "Authorization: Bearer $NIA_API_KEY" \
-H "Content-Type: application/json" \
-d '{"url": "https://sdk.vercel.ai/docs"}'
Search Across Sources
curl -X POST https://apigcp.trynia.ai/v2/universal-search \
-H "Authorization: Bearer $NIA_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"query": "How do I stream responses?",
"repositories": ["vercel/ai"],
"data_sources": ["Vercel AI SDK"]
}'
Package Search (No Indexing Required)
curl -X POST https://apigcp.trynia.ai/v2/package-search/grep \
-H "Authorization: Bearer $NIA_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"registry": "npm",
"package_name": "ai",
"pattern": "streamText"
}'
Best Practices
Use Universal Search for Multi-Source Queries
Instead of querying repositories and documentation separately, use the /universal-search endpoint to search across all your indexed sources at once:
curl -X POST https://apigcp.trynia.ai/v2/universal-search \
-H "Authorization: Bearer $NIA_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"query": "authentication middleware implementation",
"search_mode": "unified"
}'
Leverage Package Search for Dependencies
Search through 3,000+ packages across PyPI, NPM, Crates.io, and Go modules without indexing:
import requests
headers = {"Authorization": f"Bearer {NIA_API_KEY}"}
# Semantic search for understanding patterns
response = requests.post(
"https://apigcp.trynia.ai/v2/package-search/hybrid",
headers=headers,
json={
"registry": "py_pi",
"package_name": "fastapi",
"semantic_queries": ["How does dependency injection work?"]
}
)
Handle Rate Limits with Exponential Backoff
import time
import requests
def fetch_with_retry(url, headers, json_data, max_retries=3):
for attempt in range(max_retries):
response = requests.post(url, headers=headers, json=json_data)
if response.status_code == 429:
wait_time = 2 ** attempt
print(f"Rate limited. Waiting {wait_time}s...")
time.sleep(wait_time)
continue
return response
raise Exception("Max retries exceeded")
Monitor Indexing Progress
Large repositories take time to index. Poll the status endpoint:
# Check repository indexing status
curl https://apigcp.trynia.ai/v2/repositories/vercel%2Fai \
-H "Authorization: Bearer $NIA_API_KEY"
Response includes progress:
{
"repository": "vercel/ai",
"status": "indexing",
"progress": {
"percentage": 45,
"stage": "embedding",
"message": "Processing files..."
}
}
Error Handling
The Nia API uses standard HTTP status codes:
| Code | Description | Action |
|---|
| 200 | Success | Process the response normally |
| 400 | Bad Request | Check request parameters |
| 401 | Unauthorized | Verify your API key |
| 404 | Not Found | Resource doesn’t exist |
| 429 | Rate Limited | Implement backoff and retry |
| 500 | Server Error | Retry with backoff, contact support if persistent |
{
"error": "Error message describing what went wrong",
"status": 429
}
SDK & Integration Options
MCP Server (Recommended for AI Agents)
The easiest way to integrate Nia with AI coding agents:
curl -fsSL https://app.trynia.ai/cli | sh
See the Installation guide for detailed setup.
Direct API Integration
For custom applications, use the REST API directly:
JavaScript/TypeScript:
const response = await fetch("https://apigcp.trynia.ai/v2/universal-search", {
method: "POST",
headers: {
"Authorization": `Bearer ${process.env.NIA_API_KEY}`,
"Content-Type": "application/json"
},
body: JSON.stringify({
query: "How does error handling work?",
repositories: ["fastapi/fastapi"]
})
});
const results = await response.json();
Python:
import requests
headers = {
"Authorization": f"Bearer {os.environ['NIA_API_KEY']}",
"Content-Type": "application/json"
}
response = requests.post(
"https://apigcp.trynia.ai/v2/universal-search",
headers=headers,
json={
"query": "How does error handling work?",
"repositories": ["fastapi/fastapi"]
}
)
results = response.json()
Key Endpoints
| Endpoint | Description |
|---|
POST /repositories | Index a GitHub repository |
POST /data-sources | Index documentation/website |
POST /research-papers | Index arXiv papers |
POST /universal-search | Search across all sources |
POST /query | Query with chat context |
POST /package-search/grep | Regex search in packages |
POST /package-search/hybrid | Semantic search in packages |
POST /oracle | Deep research agent |
POST /contexts | Save conversation context |
POST /web-search | Search the web |
POST /deep-research | Multi-step research |
Check out the API Reference for complete endpoint documentation with request/response schemas.