SDK
Configuration
Environment variables, PapiConfig, and feature flags
Configuration
The SDK is configured through PapiConfig, which can be built programmatically or loaded from environment variables.
Environment Variables
| Variable | Description | Required | Default |
|---|---|---|---|
PAPI_API_KEY | Your PAPI API key (papi_sk_*) | Yes (managed mode) | — |
PAPI_BASE_URL | API base URL override | No | https://papi.tylerthebuildor.com |
PAPI_TIMEOUT | Request timeout in seconds | No | 30 |
PAPI_MODE | managed or direct | No | managed |
Direct Mode Variables
When using direct mode, you provide exchange credentials locally:
| Variable | Description | Exchange |
|---|---|---|
POLYMARKET_API_KEY | Polymarket CLOB API key | Polymarket |
POLYMARKET_SECRET | Polymarket CLOB API secret | Polymarket |
POLYMARKET_PASSPHRASE | Polymarket CLOB passphrase | Polymarket |
KALSHI_EMAIL | Kalshi account email | Kalshi |
KALSHI_PASSWORD | Kalshi account password | Kalshi |
PapiConfig Builder
Managed Mode
use papi_sdk::PapiConfig;
let config = PapiConfig::managed()
.api_key("papi_sk_live_...")
.base_url("https://papi.tylerthebuildor.com") // optional
.timeout(30) // optional, seconds
.build()?;Direct Mode
use papi_sdk::PapiConfig;
let config = PapiConfig::direct()
.polymarket_credentials(
"your-clob-api-key",
"your-clob-secret",
"your-passphrase",
)
.kalshi_credentials(
"your-email",
"your-password",
)
.build()?;From Environment
Load all configuration from environment variables:
use papi_sdk::PapiConfig;
let config = PapiConfig::from_env()?;This reads PAPI_MODE to determine the mode, then loads the appropriate variables.
Feature Flags
The SDK supports Cargo feature flags for controlling which exchanges are compiled:
[dependencies]
# Both exchanges (default)
papi-sdk = "0.1"
# Only Polymarket
papi-sdk = { version = "0.1", default-features = false, features = ["polymarket"] }
# Only Kalshi
papi-sdk = { version = "0.1", default-features = false, features = ["kalshi"] }| Feature | Description | Default |
|---|---|---|
polymarket | Polymarket exchange support | Yes |
kalshi | Kalshi exchange support | Yes |
managed | Managed mode (PAPI API proxy) | Yes |
direct | Direct exchange connections | Yes |
Retry Configuration
The SDK retries failed requests with exponential backoff by default:
let config = PapiConfig::managed()
.api_key_from_env()
.max_retries(3) // default: 3
.retry_delay_ms(1000) // default: 1000ms
.build()?;Retries apply to:
- Network errors (connection refused, timeout)
- 429 (rate limited) responses
- 5xx server errors
They do not apply to:
- 4xx client errors (except 429)
- Successful responses