Important: Configure your NekudaClientonce and reuse it throughout your application. Creating multiple clients with different configurations leads to confusion and bugs.
Copy
Ask AI
from nekuda import NekudaClient# Configure once at startup, typically using environment variablesclient = NekudaClient.from_env()# Or explicitly:# client = NekudaClient(api_key="sk_live_...", base_url="https://api.nekuda.ai")# Use everywhereuser_id_alice = "alice_123"user_alice = client.user(user_id_alice)user_id_bob = "bob_456"user_bob = client.user(user_id_bob)
Copy
Ask AI
from nekuda import NekudaClient# Configure once at startup, typically using environment variablesclient = NekudaClient.from_env()# Or explicitly:# client = NekudaClient(api_key="sk_live_...", base_url="https://api.nekuda.ai")# Use everywhereuser_id_alice = "alice_123"user_alice = client.user(user_id_alice)user_id_bob = "bob_456"user_bob = client.user(user_id_bob)
Copy
Ask AI
import { NekudaClient } from '@nekuda/nekuda-js';// Configure once at startupconst client = NekudaClient.fromEnv();// Or explicitly:// const client = new NekudaClient('sk_live_...', { baseUrl: 'https://api.nekuda.ai' });// Use everywhereconst userAlice = client.user('alice_123');const userBob = client.user('bob_456');
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.
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.
Uses NekudaClient.from_env(). Ensure NEKUDA_API_KEY is set.
Copy
Ask AI
from nekuda import NekudaClient# Reads NEKUDA_API_KEY and optionally NEKUDA_BASE_URLclient = NekudaClient.from_env()
Explicit Production
Copy
Ask AI
from nekuda import NekudaClientclient = NekudaClient( api_key="sk_live_your_actual_key", # Replace with your key base_url="https://api.nekuda.ai", # Default, usually not needed to set timeout=30, max_retries=3, backoff_factor=0.5,)
Staging/Testing
Copy
Ask AI
from nekuda import NekudaClient# Best to use environment variables for this:# export NEKUDA_API_KEY="sk_test_your_staging_key"# export NEKUDA_BASE_URL="https://staging-api.nekuda.ai"# client = NekudaClient.from_env()# Or explicitly:client_staging = NekudaClient( api_key="sk_test_your_staging_key", base_url="https://staging-api.nekuda.ai", timeout=10, max_retries=1,)
Production (Recommended)
Uses NekudaClient.from_env(). Ensure NEKUDA_API_KEY is set.
Copy
Ask AI
from nekuda import NekudaClient# Reads NEKUDA_API_KEY and optionally NEKUDA_BASE_URLclient = NekudaClient.from_env()
Explicit Production
Copy
Ask AI
from nekuda import NekudaClientclient = NekudaClient( api_key="sk_live_your_actual_key", # Replace with your key base_url="https://api.nekuda.ai", # Default, usually not needed to set timeout=30, max_retries=3, backoff_factor=0.5,)
Staging/Testing
Copy
Ask AI
from nekuda import NekudaClient# Best to use environment variables for this:# export NEKUDA_API_KEY="sk_test_your_staging_key"# export NEKUDA_BASE_URL="https://staging-api.nekuda.ai"# client = NekudaClient.from_env()# Or explicitly:client_staging = NekudaClient( api_key="sk_test_your_staging_key", base_url="https://staging-api.nekuda.ai", timeout=10, max_retries=1,)
Production (Recommended)
Copy
Ask AI
import { NekudaClient } from '@nekuda/nekuda-js';// From environment variablesconst client = NekudaClient.fromEnv();// Or explicitlyconst client = new NekudaClient('sk_live_...', { timeout: 30000, maxRetries: 5, backoffFactor: 1.0,});
Development
Copy
Ask AI
import { NekudaClient } from '@nekuda/nekuda-js';const client = new NekudaClient('sk_test_...', { baseUrl: 'localhost:8000', // Will become http://localhost:8000 timeout: 10000, maxRetries: 1,});
High-throughput
Copy
Ask AI
import { NekudaClient } from '@nekuda/nekuda-js';const client = new NekudaClient('sk_live_...', { timeout: 60000, // Longer timeout for complex operations maxRetries: 10, // More aggressive retries backoffFactor: 0.3, // Faster initial retries});
This is the most flexible for different deployment environments (dev, staging, prod).
.env example
Copy
Ask AI
# For productionNEKUDA_API_KEY=sk_live_xxxxxxxxxxxxNEKUDA_BASE_URL=https://api.nekuda.ai# For staging# NEKUDA_API_KEY=sk_test_yyyyyyyyyyyy# NEKUDA_BASE_URL=https://staging-api.nekuda.ai
Python Code
Copy
Ask AI
from nekuda import NekudaClientclient = NekudaClient.from_env()
You can use from_env() and override specific parameters.
Copy
Ask AI
from nekuda import NekudaClient# Assumes NEKUDA_API_KEY and NEKUDA_BASE_URL are set in environmentclient = NekudaClient.from_env( timeout=60, # Override default timeout max_retries=5 # Override default retries)
For quick scripts or simple applications, you can register a single global client.
Copy
Ask AI
from nekuda import NekudaClient, set_default_client, get_default_client# Set once at startup, typically using environment configurationset_default_client(NekudaClient.from_env())# Use anywhere in your code without passing the client instancedef some_function(): client = get_default_client() # user_id must still be provided to client.user() user_context = client.user("some_user_id") # ... use user_context.create_mandate(...)
Copy
Ask AI
from nekuda import NekudaClient, set_default_client, get_default_client# Set once at startup, typically using environment configurationset_default_client(NekudaClient.from_env())# Use anywhere in your code without passing the client instancedef some_function(): client = get_default_client() # user_id must still be provided to client.user() user_context = client.user("some_user_id") # ... use user_context.create_mandate(...)
Copy
Ask AI
import { NekudaClient, setDefaultClient, getDefaultClient } from '@nekuda/nekuda-js';// Set once at startupsetDefaultClient(NekudaClient.fromEnv());// Use anywhere in your codeasync function someFunction() { const client = getDefaultClient(); const user = client.user('some_user_id'); // ... use user.createMandate(...)}
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.
The SDK automatically validates all API responses.
Automatic Response Validation Details
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.
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.
Detects HTML error pages (e.g., nginx errors, gateway timeouts) and throws NekudaApiError.
Validates JSON structure and throws NekudaApiError if parsing fails.
Validates response data against TypeScript interfaces.
Provides clear error messages with details about the validation issue.
Enable detailed logging from the SDK to troubleshoot issues.
Copy
Ask AI
import logging# To see all SDK debug messages, including request/response details:logging.basicConfig(level=logging.DEBUG) # Set root logger to DEBUG# Or more targeted:# logging.getLogger("nekuda").setLevel(logging.DEBUG)# Example output you might see:# DEBUG:nekuda.client:Making POST request to https://api.nekuda.ai/v1/mandates with headers: ..., payload: ...# DEBUG:nekuda.client:Received 201 response from https://api.nekuda.ai/v1/mandates with data: {"mandate_id": ...}
Copy
Ask AI
import logging# To see all SDK debug messages, including request/response details:logging.basicConfig(level=logging.DEBUG) # Set root logger to DEBUG# Or more targeted:# logging.getLogger("nekuda").setLevel(logging.DEBUG)# Example output you might see:# DEBUG:nekuda.client:Making POST request to https://api.nekuda.ai/v1/mandates with headers: ..., payload: ...# DEBUG:nekuda.client:Received 201 response from https://api.nekuda.ai/v1/mandates with data: {"mandate_id": ...}
Copy
Ask AI
// Set environment variable before creating clientprocess.env.NEKUDA_DEBUG = 'true';const client = new NekudaClient('sk_...', { debug: true });// Example output:// DEBUG:nekuda:Making POST request to https://api.nekuda.ai/api/v1/mandate/create// DEBUG:nekuda:Response status: 200// DEBUG:nekuda:Response data: {'mandateId': 123, ...}
Yes – pass max_retries=0 to the NekudaClient constructor.
Does the SDK support async calls?
Currently, the Python SDK only supports synchronous calls. An async variant (AsyncNekudaClient) is on the roadmap.
Currently, the Python SDK only supports synchronous calls. An async variant (AsyncNekudaClient) is on the roadmap.
The TypeScript SDK only supports asynchronous calls. All methods return Promises and should be used with async/await or .then().
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:
Copy
Ask AI
import osfrom nekuda import NekudaClientif os.getenv("APP_ENV") == "production": client = NekudaClient(api_key=os.getenv("PROD_NEKUDA_API_KEY"), base_url="https://api.nekuda.ai")elif os.getenv("APP_ENV") == "staging": client = NekudaClient(api_key=os.getenv("STAGING_NEKUDA_API_KEY"), base_url="https://staging-api.nekuda.ai")else: # Default to a local or test setup client = NekudaClient(api_key="sk_test_local_key", base_url="http://localhost:8000")
Assistant
Responses are generated using AI and may contain mistakes.