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 (managed mode)
PAPI_BASE_URLAPI base URL overrideNohttps://papi.tylerthebuildor.com
PAPI_TIMEOUTRequest timeout in secondsNo30
PAPI_MODEmanaged or directNomanaged

Direct Mode Variables

When using direct mode, you provide exchange credentials locally:

VariableDescriptionExchange
POLYMARKET_API_KEYPolymarket CLOB API keyPolymarket
POLYMARKET_SECRETPolymarket CLOB API secretPolymarket
POLYMARKET_PASSPHRASEPolymarket CLOB passphrasePolymarket
KALSHI_EMAILKalshi account emailKalshi
KALSHI_PASSWORDKalshi account passwordKalshi

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:

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
managedManaged mode (PAPI API proxy)Yes
directDirect exchange connectionsYes

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