PAPI
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

VariableDescriptionRequiredDefault
PAPI_API_KEYYour PAPI API key (papi_sk_*)Yes
PAPI_BASE_URLAPI base URL overrideNohttps://api.papi.market
PAPI_TIMEOUTRequest timeout in secondsNo30

PapiConfig Builder

use papi_sdk::PapiConfig;

let config = PapiConfig::managed()
    .api_key("<your-api-key>")
    .base_url("https://api.papi.market")  // optional
    .timeout(30)                          // optional, seconds
    .build()?;

From Environment

Load configuration from environment variables:

use papi_sdk::PapiConfig;

let config = PapiConfig::from_env()?;

Feature Flags

The SDK supports Cargo feature flags for controlling which exchanges are compiled:

Cargo.toml
[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"] }
FeatureDescriptionDefault
polymarketPolymarket exchange supportYes
kalshiKalshi exchange supportYes

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

On this page