Skip to main content

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:
HeaderDescription
X-RateLimit-LimitRate limit ceiling for the endpoint
X-RateLimit-RemainingRemaining requests in current window
X-RateLimit-ResetTime when the rate limit resets
X-Monthly-LimitMonthly 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:
CodeDescriptionAction
200SuccessProcess the response normally
400Bad RequestCheck request parameters
401UnauthorizedVerify your API key
404Not FoundResource doesn’t exist
429Rate LimitedImplement backoff and retry
500Server ErrorRetry with backoff, contact support if persistent

Error Response Format

{
  "error": "Error message describing what went wrong",
  "status": 429
}

SDK & Integration Options

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

EndpointDescription
POST /repositoriesIndex a GitHub repository
POST /data-sourcesIndex documentation/website
POST /research-papersIndex arXiv papers
POST /universal-searchSearch across all sources
POST /queryQuery with chat context
POST /package-search/grepRegex search in packages
POST /package-search/hybridSemantic search in packages
POST /oracleDeep research agent
POST /contextsSave conversation context
POST /web-searchSearch the web
POST /deep-researchMulti-step research
Check out the API Reference for complete endpoint documentation with request/response schemas.