VelocitySDK
Constructor
| Property | Type | Required | Default | Description |
|---|---|---|---|---|
publisherKey | string | Yes | — | Your unique publisher key from Velocity |
timeout | number | No | 30000 | Request timeout in milliseconds |
retries | number | No | 0 | Number of retry attempts (max 3) |
logger | Logger | No | console | Custom logger implementation |
sdkMode | 'development' | 'production' | No | — | Development mode returns mock ads. For local testing only |
init()
Initializes the SDK and establishes a session. Must be called before fetchAd().
| Parameter | Type | Required | Description |
|---|---|---|---|
publisherUserId | string | No | Unique identifier for the user |
InitResponse
fetchAd()
Fetches a contextual ad. SDK must be initialized first.
| Parameter | Type | Required | Description |
|---|---|---|---|
prompt | string | Yes | User’s query or prompt text |
aiResponse | string | Yes | AI-generated response text |
dimensions | { width: number; height: number } | Yes | Ad container dimensions in pixels |
adUnitId | string | No | Optional identifier for the ad placement |
FetchAdResponse
data.ads are sorted by bidPrice descending — use ads[0] for the winning ad.
Example
VelocitySDKError
All SDK errors are instances ofVelocitySDKError.
| Property | Type | Description |
|---|---|---|
message | string | Human-readable error description |
code | string | Error code |
statusCode | number | undefined | HTTP status code, if applicable |
Error Codes
| Code | Description | When It Occurs |
|---|---|---|
VALIDATION_ERROR | Invalid parameters | Required parameters missing or invalid |
AUTH_ERROR | Authentication failed | publisherKey invalid or unauthorized |
CONFIG_ERROR | SDK misconfigured | Invalid SDK configuration at init |
NETWORK_ERROR | Network failure | Request fails due to connectivity or timeout |
AD_SERVER_ERROR | Server error | Ad server unavailable or unexpected error |

