SDK Cliente
Integracion rápida con JavaScript SDK — sin dependencias, listo para browser y Node.js
- Quick Start
- Authentication
- Forecast API
- Decision APIs
- Explainability
- Real-time Events
- Error Handling
- Try It
Quick Start
Installation
Include the SDK via a script tag or import it in your bundler. No npm packages required.
Browser (CDN / self-hosted)
Node.js / Bundler
Basic Usage
Authentication
API Key Setup
All requests are authenticated via an X-API-Key header.
Obtain your key from the Customer Portal and pass it to the constructor.
If no apiKey is provided, the SDK omits the header,
which is useful for local development against an unauthenticated backend.
| Option | Type | Description |
|---|---|---|
| apiKey | string | Your AgroClimaX API key (prefix clmx_) |
| baseUrl | string | API base URL. Defaults to '' (current origin) |
Forecast API
forecast(opts)
Trigger a forecast run and return results.
| Param | Type | Description |
|---|---|---|
| model | string? | Model name, e.g. 'AIFS Single' |
| lat | number | Latitude (required) |
| lon | number | Longitude (required) |
| lead_hours | number? | Lead time in hours |
| variables | string[]? | Variable codes, e.g. ['2t','tp'] |
nowcast(opts)
Short-range nowcast (0-6 hours) at high temporal resolution.
| Param | Type | Description |
|---|---|---|
| lat | number | Latitude (required) |
| lon | number | Longitude (required) |
| lead_minutes | number? | Lead time in minutes (default: 360) |
| variables | string[]? | Variable codes |
models(), datasets(), benchmarks()
Retrieve platform catalogs.
Decision APIs
frostRisk(opts)
Evaluate frost probability and severity for a location.
| Param | Type | Description |
|---|---|---|
| lat | number | Latitude (required) |
| lon | number | Longitude (required) |
| lead_hours | number? | Forecast horizon in hours |
heatStress(opts)
Compute heat stress index (WBGT) for a location.
renewablesWindow(opts)
Find optimal production windows for renewable energy assets.
agriAssess(opts)
Comprehensive agricultural weather assessment for a field location.
| Param | Type | Description |
|---|---|---|
| lat | number | Latitude (required) |
| lon | number | Longitude (required) |
| crop_type | string? | e.g. 'soy', 'wheat', 'rice' |
energyAssess(opts)
Energy production forecast and curtailment risk assessment.
| Param | Type | Description |
|---|---|---|
| lat | number | Latitude (required) |
| lon | number | Longitude (required) |
| asset_type | string | 'solar' or 'wind' (required) |
| capacity_mw | number? | Installed capacity in MW |
Explainability
provenance(runId)
Retrieve the full provenance chain for a forecast run: data sources, model version, pipeline steps, and license metadata.
narrative(runId)
Generate a human-readable narrative explaining the forecast in natural language, including confidence levels and key drivers.
Real-time Events
subscribe(onEvent) / unsubscribe()
Subscribe to platform events via Server-Sent Events. Receive live updates for completed forecasts, new alerts, and system status changes.
The SSE connection auto-reconnects on network errors.
Error events are delivered to your callback with type: 'error'.
Error Handling
Try/Catch Pattern
All async SDK methods throw an Error when the server returns a non-2xx response.
The error object includes status (HTTP code) and body (parsed JSON).
Common Error Codes
| Status | Meaning | Action |
|---|---|---|
| 401 | Unauthorized | Check your API key |
| 403 | Forbidden | Key lacks required scope |
| 422 | Validation Error | Check request parameters |
| 429 | Rate Limited | Back off and retry |
| 500 | Server Error | Retry or contact support |