Skip to main content

Configuration

Environment Variables​

The SDK reads the following environment variables. Set them before creating a client.

Required​

VariableDescription
SCOPE_ORG_IDYour organization identifier
SCOPE_API_KEYAPI key ID for authentication
SCOPE_API_SECRETAPI key secret for authentication
SCOPE_API_URLBase URL for the Scope API
SCOPE_AUTH_API_URLAuth API URL for token exchange

Optional​

VariableDefaultDescription
SCOPE_ENVIRONMENTproductionEnvironment name (e.g., staging)
SCOPE_TOKEN_REFRESH_BUFFER60Seconds before token expiry to trigger a refresh

Credentials​

Create credentials explicitly or load them from environment variables:

from scope_client import ApiKeyCredentials

# From environment variables
credentials = ApiKeyCredentials.from_env()

# Or explicitly
credentials = ApiKeyCredentials(
org_id="my-org",
api_key="key_abc123",
api_secret="secret_xyz",
)

Client Configuration Options​

All options can be passed when creating a client:

OptionTypeDefaultDescription
credentialsCredentialsrequiredAuthentication credentials
base_urlstringfrom SCOPE_API_URLBase URL for the API
auth_api_urlstringfrom SCOPE_AUTH_API_URLAuth API URL
api_versionstring"v1"API version string
timeoutinteger30Request timeout in seconds
open_timeoutinteger10Connection timeout in seconds
cache_enabledbooleantrueEnable response caching
cache_ttlinteger300Cache time-to-live in seconds
max_retriesinteger3Maximum retry attempts
retry_base_delayfloat0.5Base delay between retries in seconds
retry_max_delayfloat30.0Maximum delay between retries in seconds
telemetry_enabledbooleantrueEnable telemetry hooks
environmentstring"production"Environment name
token_refresh_bufferinteger60Seconds before token expiry to refresh

Creating a Client​

Direct instantiation​

from scope_client import ScopeClient, ApiKeyCredentials

credentials = ApiKeyCredentials.from_env()
client = ScopeClient(
credentials=credentials,
cache_ttl=600,
timeout=60,
)

Global configuration​

Set defaults once and create clients from the global configuration:

import scope_client
from scope_client import ApiKeyCredentials

# Configure globally
scope_client.configure(
credentials=ApiKeyCredentials.from_env(),
cache_enabled=True,
cache_ttl=600,
)

# Create a client using the global configuration
client = scope_client.client()

# Override specific options per-client
client2 = scope_client.client(cache_enabled=False)

Context manager (Python)​

The Python client supports the context manager protocol for automatic cleanup:

with ScopeClient(credentials=credentials) as client:
version = client.get_prompt_version("greeting")
print(version.render(name="Alice"))
# Connection is closed automatically
Was this page helpful?