Skip to main content

Getting Your API Key

1

Create an account

Go to app.trynia.ai and sign in or create a new account.
2

Navigate to API Keys

Open Settings → API Keys from the sidebar.
3

Generate a key

Click Create new API key, give it a name, and copy the key. You won’t be able to see it again.
Keep your API key secure. Never commit it to version control or expose it in client-side code.

Client Setup

from nia_py.sdk import NiaSDK

sdk = NiaSDK(api_key="nia_your_api_key")

Low-Level Client

For full control over individual API calls, use the underlying authenticated client directly.
from nia_py import AuthenticatedClient

client = AuthenticatedClient(
    base_url="https://apigcp.trynia.ai/v2",
    token="nia_your_api_key",
)

Environment Variables

Store your API key in an environment variable instead of hardcoding it:
export NIA_API_KEY="nia_your_api_key"
import os
from nia_py.sdk import NiaSDK

sdk = NiaSDK(api_key=os.environ["NIA_API_KEY"])

Advanced Configuration

Request Timeout

sdk = NiaSDK(
    api_key=os.environ["NIA_API_KEY"],
    timeout_seconds=120.0,  # default: 60s
)
For the low-level client, pass an httpx.Timeout:
import httpx
from nia_py import AuthenticatedClient

client = AuthenticatedClient(
    base_url="https://apigcp.trynia.ai/v2",
    token="nia_your_api_key",
    timeout=httpx.Timeout(120.0),
)

Retry Configuration

Both SDKs include automatic retries with exponential backoff for server errors (5xx) and network failures.
sdk = NiaSDK(
    api_key="nia_your_api_key",
    max_retries=3,                   # default: 2
    initial_backoff_seconds=1.0,     # default: 0.5
)
# Backoff: 1s → 2s → 4s

Context Manager (Python)

The Python low-level client supports context managers for automatic resource cleanup:
from nia_py import AuthenticatedClient
from nia_py.api.v2_api import list_repositories_v2_v2_repositories_get

with AuthenticatedClient(
    base_url="https://apigcp.trynia.ai/v2",
    token="nia_your_api_key",
) as client:
    repos = list_repositories_v2_v2_repositories_get.sync(client=client)
Or async:
async with AuthenticatedClient(
    base_url="https://apigcp.trynia.ai/v2",
    token="nia_your_api_key",
) as client:
    repos = await list_repositories_v2_v2_repositories_get.asyncio(client=client)

Rate Limits

API rate limits depend on your plan:
PlanRequests/minIndexed Sources
Free103
Pro60Unlimited
EnterpriseCustomUnlimited
Rate limit headers are included in every response:
  • X-RateLimit-Limit — maximum requests allowed
  • X-RateLimit-Remaining — requests remaining in window
  • X-RateLimit-Reset — seconds until window resets

Error Handling

High-level SDK raises typed exceptions:
from nia_py.sdk import NiaSDK
from nia_py.sdk.errors import NiaAPIError, NiaTimeoutError

sdk = NiaSDK(api_key="nia_your_api_key")

try:
    result = sdk.search.universal(query="test")
except NiaAPIError as e:
    print(f"API error {e.status_code}: {e}")
except NiaTimeoutError as e:
    print(f"Operation timed out: {e}")
Low-level client returns Response objects with status codes:
from nia_py.api.v2_api import list_repositories_v2_v2_repositories_get

response = list_repositories_v2_v2_repositories_get.sync_detailed(client=client)

if response.status_code == 200:
    print(response.parsed)
elif response.status_code == 401:
    print("Invalid API key")
elif response.status_code == 429:
    print("Rate limited — retry after:", response.headers.get("Retry-After"))

Authentication Methods

The API accepts your key via either header:
HeaderFormat
AuthorizationBearer nia_your_api_key
X-API-Keynia_your_api_key
Both SDKs use the Authorization: Bearer format by default. The Python low-level client allows customizing the header:
client = AuthenticatedClient(
    base_url="https://apigcp.trynia.ai/v2",
    token="nia_your_api_key",
    prefix="Bearer",                  # default
    auth_header_name="Authorization", # default
)