Configuration Consistency 🎯
Important: Configure your
NekudaClient
once and reuse it throughout your application. Creating multiple clients with different configurations leads to confusion and bugs.- Python
- TypeScript
Environment Variables
These are the primary way to configure the nekuda SDK.Variable | Description | Default |
---|---|---|
NEKUDA_API_KEY | Required – Secret key identifying your nekuda account. Get this from the nekuda customer portal. | – |
NEKUDA_BASE_URL | Override the API host. Defaults to production. Useful for pointing to staging or local mock servers. | https://api.nekuda.ai |
NekudaClient.from_env()
.
Example .env file
.env
Client Constructor Options
While environment variables are recommended, you can also configure the client directly.- Python
- TypeScript
Your nekuda API key (starts with
sk_live_
or sk_test_
). This is mandatory.API endpoint. The SDK automatically normalizes this (e.g., adds
https://
, removes trailing /
). Only change this if you need to point to a non-production environment like staging.Network timeout in seconds passed to the underlying
httpx
client.How many times to automatically retry on 5xx (server errors) or 429 (rate limit) responses.
Exponential sleep multiplier between retries.
sleep = (2 ** (retry_attempt - 1)) * backoff_factor
.URL Normalization 🎯
The SDK automatically normalizes thebase_url
. The default is https://api.nekuda.ai
.
URL Normalization Features
URL Normalization Features
The SDK will:
- Add
https://
if no protocol specified (assumingapi.nekuda.ai
or similar public TLDs). - Remove trailing slashes.
- Validate the URL format.
For local development URLs like
localhost:8000
, ensure you includehttp://
if not using HTTPS.
Configuration Examples
- Python
- TypeScript
Production (Recommended)
Production (Recommended)
Uses
NekudaClient.from_env()
. Ensure NEKUDA_API_KEY
is set.Explicit Production
Explicit Production
Staging/Testing
Staging/Testing
Configuration Patterns
Pattern 1: Environment Variables (Recommended)
This is the most flexible for different deployment environments (dev, staging, prod)..env example
Python Code
Pattern 2: Explicit Configuration
Useful if environment variables are not an option, or for quick local tests.Pattern 3: Mixed Configuration (Overrides)
You can usefrom_env()
and override specific parameters.
Global Default Client
For quick scripts or simple applications, you can register a single global client.- Python
- TypeScript
Using a global client can make testing and managing configurations in larger applications more complex. Be mindful of where and how the client is configured. Never share secrets (API key) across process boundaries unless you understand the security implications.
Advanced Features (Built-in)
These features are enabled by default in the nekuda SDK.Response Validation
The SDK automatically validates all API responses.Automatic Response Validation Details
Automatic Response Validation Details
- Python
- TypeScript
- Detects HTML error pages (e.g., nginx errors, gateway timeouts) and raises
NekudaApiError
. - Validates JSON structure and raises
NekudaApiError
if parsing fails. - Validates response data against expected Pydantic models (e.g., for card numbers, dates) and raises
NekudaValidationError
if data is malformed or missing. - Provides clear error messages pinpointing the validation issue.
Type Safety
All methods return typed response models, enabling IDE autocompletion and static analysis.- Python
- TypeScript
Proxy Support
The SDK supports standard proxy environment variables (HTTP_PROXY
, HTTPS_PROXY
, NO_PROXY
).
Example Proxy Configuration
No special SDK configuration is needed for proxies if these environment variables are set before your script runs.
Logging & Debugging
Enable detailed logging from the SDK to troubleshoot issues.- Python
- TypeScript
Configuration FAQ
Can I disable retries entirely?
Can I disable retries entirely?
Yes – pass
max_retries=0
to the NekudaClient
constructor.Does the SDK support async calls?
Does the SDK support async calls?
- Python
- TypeScript
Currently, the Python SDK only supports synchronous calls. An async variant (
AsyncNekudaClient
) is on the roadmap.How do I handle different environments (dev/staging/prod)?
How do I handle different environments (dev/staging/prod)?
Recommended: Use environment variables (
NEKUDA_API_KEY
, NEKUDA_BASE_URL
) and NekudaClient.from_env()
. Your deployment process can set these variables appropriately for each environment.Alternatively, you can explicitly instantiate NekudaClient
with different parameters based on an environment flag: