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://api.papi.market
PAPI_TIMEOUTRequest timeout in secondsNo30
PAPI_MODEmanaged or directNomanaged

Direct Mode Variables

When using direct mode, you provide exchange credentials locally:

VariableDescriptionExchange
POLYMARKET_PRIVATE_KEYEthereum wallet private key (0x-prefixed, 66 chars)Polymarket
KALSHI_EMAILKalshi account emailKalshi
KALSHI_PASSWORDKalshi account passwordKalshi

The SDK derives Polymarket CLOB API credentials (api_key, secret, passphrase) and wallet address automatically from the private key via EIP-712 authentication.

PapiConfig Builder

Managed Mode

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()?;

Direct Mode

use papi_sdk::PapiConfig;

let config = PapiConfig::direct()
    .polymarket_private_key("0x-your-wallet-private-key")
    .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