Configuration API Reference¶
Complete API reference for SDK configuration.
Global Configuration¶
Configuration Classes¶
STKAIConfig
dataclass
¶
Global configuration for the stkai SDK.
Aggregates all configuration sections: sdk, auth, rqc, agent, file_upload,
and rate_limit. Access via the global STKAI.config property.
Attributes:
| Name | Type | Description |
|---|---|---|
sdk |
SdkConfig
|
SDK metadata (version, cli_mode). Read-only. |
auth |
AuthConfig
|
Authentication configuration. |
rqc |
RqcConfig
|
RemoteQuickCommand configuration. |
agent |
AgentConfig
|
Agent configuration. |
file_upload |
FileUploadConfig
|
File upload configuration. |
rate_limit |
RateLimitConfig
|
Rate limiting configuration for HTTP clients. |
Example
from stkai import STKAI STKAI.config.sdk.version '0.2.8' STKAI.config.sdk.cli_mode True STKAI.config.rqc.request_timeout 30 STKAI.config.auth.has_credentials() False STKAI.config.file_upload.base_url 'https://data-integration-api.stackspot.com' STKAI.config.rate_limit.enabled False
Source code in src/stkai/_config.py
1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 | |
Functions¶
with_env_vars ¶
Return a new config with environment variables applied on top.
Reads STKAI_* environment variables and applies them over the current configuration values.
Returns:
| Type | Description |
|---|---|
STKAIConfig
|
New STKAIConfig instance with env vars applied. |
Example
config = STKAIConfig().with_env_vars()
Or apply on top of custom config¶
custom = STKAIConfig(rqc=RqcConfig(request_timeout=60)) final = custom.with_env_vars()
Source code in src/stkai/_config.py
with_cli_defaults ¶
Return a new config with CLI-provided values applied.
CLI values take precedence over env vars. When running in CLI mode, the CLI knows the correct endpoints for the current environment.
Returns:
| Type | Description |
|---|---|
STKAIConfig
|
New STKAIConfig instance with CLI values applied. |
Example
Apply CLI defaults on top of env vars¶
config = STKAIConfig().with_env_vars().with_cli_defaults()
Source code in src/stkai/_config.py
with_section_overrides ¶
with_section_overrides(*, auth: dict[str, Any] | None = None, rqc: dict[str, Any] | None = None, agent: dict[str, Any] | None = None, file_upload: dict[str, Any] | None = None, rate_limit: dict[str, Any] | None = None) -> STKAIConfig
Return a new config with overrides applied to nested sections.
Each section dict is merged with the existing section config, only overriding the specified fields.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
auth
|
dict[str, Any] | None
|
Authentication config overrides. |
None
|
rqc
|
dict[str, Any] | None
|
RemoteQuickCommand config overrides. |
None
|
agent
|
dict[str, Any] | None
|
Agent config overrides. |
None
|
file_upload
|
dict[str, Any] | None
|
File upload config overrides. |
None
|
rate_limit
|
dict[str, Any] | None
|
Rate limiting config overrides. |
None
|
Returns:
| Type | Description |
|---|---|
STKAIConfig
|
New STKAIConfig instance with overrides applied. |
Example
config = STKAIConfig() custom = config.with_section_overrides( ... rqc={"request_timeout": 60}, ... agent={"request_timeout": 120}, ... )
Source code in src/stkai/_config.py
explain_data ¶
Return config data structured for explain output.
Provides a structured representation of all config values and their sources, useful for debugging, testing, or custom formatting.
Returns:
| Type | Description |
|---|---|
dict[str, list[ConfigEntry]]
|
Dict mapping section names to list of ConfigEntry objects. |
Example
config = STKAIConfig().with_env_vars() data = config.explain_data() for entry in data["rqc"]: ... print(f"{entry.name}: {entry.value} ({entry.source})") request_timeout: 30 (default) ...
Source code in src/stkai/_config.py
SdkConfig
dataclass
¶
SDK metadata (read-only, not configurable).
Provides information about the SDK version and runtime environment. These values are automatically detected and cannot be overridden.
Attributes:
| Name | Type | Description |
|---|---|---|
version |
str
|
The installed SDK version. |
cli_mode |
bool
|
Whether StackSpot CLI (oscli) is available. |
Example
from stkai import STKAI STKAI.config.sdk.version '0.2.8' STKAI.config.sdk.cli_mode True
Source code in src/stkai/_config.py
AuthConfig
dataclass
¶
Bases: OverridableConfig
Authentication configuration for StackSpot AI.
Credentials are used for standalone authentication without StackSpot CLI. When using oscli-based HTTP clients, authentication is delegated to the CLI.
Attributes:
| Name | Type | Description |
|---|---|---|
client_id |
str | None
|
StackSpot client ID for authentication. Env var: STKAI_AUTH_CLIENT_ID |
client_secret |
str | None
|
StackSpot client secret for authentication. Env var: STKAI_AUTH_CLIENT_SECRET |
token_url |
str
|
OAuth2 token endpoint URL for client credentials flow. Env var: STKAI_AUTH_TOKEN_URL |
Example
from stkai import STKAI if STKAI.config.auth.has_credentials(): ... print("Credentials configured")
Source code in src/stkai/_config.py
Functions¶
has_credentials ¶
validate ¶
Validate auth configuration fields.
Source code in src/stkai/_config.py
RqcConfig
dataclass
¶
Bases: OverridableConfig
Configuration for RemoteQuickCommand clients.
These settings are used as defaults when creating RemoteQuickCommand instances without explicitly providing CreateExecutionOptions or GetResultOptions.
Attributes:
| Name | Type | Description |
|---|---|---|
request_timeout |
int
|
HTTP request timeout in seconds for API calls. Env var: STKAI_RQC_REQUEST_TIMEOUT |
retry_max_retries |
int
|
Maximum retry attempts for failed create-execution calls. Use 0 to disable retries (single attempt only). Use 3 for 4 total attempts (1 original + 3 retries). Env var: STKAI_RQC_RETRY_MAX_RETRIES |
retry_initial_delay |
float
|
Initial delay in seconds for the first retry attempt. Subsequent retries use exponential backoff (delay doubles each attempt). Example: with 0.5s initial delay, retries wait 0.5s, 1s, 2s, 4s... Env var: STKAI_RQC_RETRY_INITIAL_DELAY |
poll_interval |
float
|
Seconds to wait between polling status checks. Env var: STKAI_RQC_POLL_INTERVAL |
poll_max_duration |
float
|
Maximum seconds to wait for execution completion before timing out. Env var: STKAI_RQC_POLL_MAX_DURATION |
poll_overload_timeout |
float
|
Maximum seconds to tolerate CREATED status before assuming server overload. Env var: STKAI_RQC_POLL_OVERLOAD_TIMEOUT |
max_workers |
int
|
Maximum number of concurrent threads for execute_many(). Env var: STKAI_RQC_MAX_WORKERS |
base_url |
str
|
Base URL for the RQC API. If None, uses StackSpot CLI. Env var: STKAI_RQC_BASE_URL |
Example
from stkai import STKAI STKAI.config.rqc.request_timeout 30 STKAI.config.rqc.retry_max_retries 3
Source code in src/stkai/_config.py
335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 | |
Functions¶
validate ¶
Validate RQC configuration fields.
Source code in src/stkai/_config.py
AgentConfig
dataclass
¶
Bases: OverridableConfig
Configuration for Agent clients.
These settings are used as defaults when creating Agent instances without explicitly providing AgentOptions.
Attributes:
| Name | Type | Description |
|---|---|---|
request_timeout |
int
|
HTTP request timeout in seconds for chat requests. Env var: STKAI_AGENT_REQUEST_TIMEOUT |
base_url |
str
|
Base URL for the Agent API. Env var: STKAI_AGENT_BASE_URL |
retry_max_retries |
int
|
Maximum number of retry attempts for failed chat calls. Use 0 to disable retries (single attempt only). Use 3 for 4 total attempts (1 original + 3 retries). Env var: STKAI_AGENT_RETRY_MAX_RETRIES |
retry_initial_delay |
float
|
Initial delay in seconds for the first retry attempt. Subsequent retries use exponential backoff (delay doubles each attempt). Example: with 0.5s initial delay, retries wait 0.5s, 1s, 2s, 4s... Env var: STKAI_AGENT_RETRY_INITIAL_DELAY |
max_workers |
int
|
Maximum number of concurrent threads for chat_many(). Env var: STKAI_AGENT_MAX_WORKERS |
Example
from stkai import STKAI STKAI.config.agent.request_timeout 60 STKAI.config.agent.base_url 'https://genai-inference-app.stackspot.com' STKAI.config.agent.retry_max_retries 0
Source code in src/stkai/_config.py
Functions¶
validate ¶
Validate Agent configuration fields.
Source code in src/stkai/_config.py
RateLimitConfig
dataclass
¶
Bases: OverridableConfig
Configuration for HTTP client rate limiting.
When enabled, the EnvironmentAwareHttpClient automatically wraps the underlying HTTP client with rate limiting based on the selected strategy.
Available strategies
- "token_bucket": Simple Token Bucket algorithm. Limits requests to max_requests per time_window. Blocks if limit exceeded.
- "adaptive": Adaptive rate limiting with AIMD (Additive Increase, Multiplicative Decrease). Automatically adjusts rate based on HTTP 429 responses from the server.
Note: HTTP 429 retry logic is handled by the Retrying class, not the rate limiter. The adaptive strategy only applies AIMD penalty on 429 responses.
Attributes:
| Name | Type | Description |
|---|---|---|
enabled |
bool
|
Whether to enable rate limiting. Env var: STKAI_RATE_LIMIT_ENABLED |
strategy |
RateLimitStrategy
|
Rate limiting strategy to use. Env var: STKAI_RATE_LIMIT_STRATEGY |
max_requests |
int
|
Maximum requests allowed in the time window. Env var: STKAI_RATE_LIMIT_MAX_REQUESTS |
time_window |
float
|
Time window in seconds for the rate limit. Env var: STKAI_RATE_LIMIT_TIME_WINDOW |
max_wait_time |
float | None
|
Maximum seconds to wait for a token before raising TokenAcquisitionTimeoutError. None means wait indefinitely. Env var: STKAI_RATE_LIMIT_MAX_WAIT_TIME |
min_rate_floor |
float
|
(adaptive only) Minimum rate as fraction of max_requests. Prevents rate from dropping below this floor. Env var: STKAI_RATE_LIMIT_MIN_RATE_FLOOR |
penalty_factor |
float
|
(adaptive only) Rate reduction factor on 429 (0-1). Env var: STKAI_RATE_LIMIT_PENALTY_FACTOR |
recovery_factor |
float
|
(adaptive only) Rate increase factor on success (0-1). Env var: STKAI_RATE_LIMIT_RECOVERY_FACTOR |
Example
from stkai import STKAI STKAI.configure( ... rate_limit={ ... "enabled": True, ... "strategy": "token_bucket", ... "max_requests": 10, ... "time_window": 60.0, ... } ... )
Or with adaptive strategy¶
STKAI.configure( ... rate_limit={ ... "enabled": True, ... "strategy": "adaptive", ... "max_requests": 100, ... "min_rate_floor": 0.1, ... } ... )
Source code in src/stkai/_config.py
591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 | |
Functions¶
with_overrides ¶
Return a new instance with specified fields overridden.
Extends base implementation to support special values: - max_wait_time: Can be None, a float, or "unlimited"/"none"/"null" (strings are converted to None for unlimited waiting).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
overrides
|
dict[str, Any]
|
Dict of field names to new values. |
required |
allow_none_fields
|
set[str] | None
|
Additional fields that accept None (merged with max_wait_time). |
None
|
Returns:
| Type | Description |
|---|---|
Self
|
New instance with updated values. |
Source code in src/stkai/_config.py
with_env_vars ¶
Override to handle max_wait_time (can be None for 'unlimited').
Source code in src/stkai/_config.py
validate ¶
Validate rate limit configuration fields.
Source code in src/stkai/_config.py
conservative_preset
classmethod
¶
Conservative rate limiting preset.
Prioritizes stability over throughput. Best for: - Critical batch jobs - CI/CD pipelines - Scenarios with many concurrent processes
Behavior: - Waits up to 120s for tokens (patient, but not forever) - Aggressive penalty on 429 (halves rate) - Slow recovery (2% per success) - Can drop to 5% of max_requests under stress
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
max_requests
|
int
|
Maximum requests allowed in the time window. Calculate based on your quota and expected concurrent processes. Default assumes ~5 processes sharing a 100 req/min quota. |
20
|
time_window
|
float
|
Time window in seconds for the rate limit. |
60.0
|
Returns:
| Type | Description |
|---|---|
RateLimitConfig
|
RateLimitConfig with conservative settings. |
Example
Quota of 100 req/min, expect ~5 processes¶
config = RateLimitConfig.conservative_preset(max_requests=20)
Quota of 200 req/min, expect ~4 processes¶
config = RateLimitConfig.conservative_preset(max_requests=50)
Source code in src/stkai/_config.py
balanced_preset
classmethod
¶
Balanced rate limiting preset (recommended).
Sensible defaults for most use cases. Best for: - General batch processing - 2-5 concurrent processes - When unsure which preset to use
Behavior: - Waits up to 45s for tokens - Moderate penalty on 429 (30% reduction) - Medium recovery (5% per success) - Can drop to 10% of max_requests under stress
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
max_requests
|
int
|
Maximum requests allowed in the time window. Calculate based on your quota and expected concurrent processes. Default assumes ~2-5 processes sharing a 100 req/min quota. |
40
|
time_window
|
float
|
Time window in seconds for the rate limit. |
60.0
|
Returns:
| Type | Description |
|---|---|
RateLimitConfig
|
RateLimitConfig with balanced settings. |
Example
Quota of 100 req/min, expect ~2 processes¶
config = RateLimitConfig.balanced_preset(max_requests=50)
Use defaults (good for typical scenarios)¶
config = RateLimitConfig.balanced_preset()
Source code in src/stkai/_config.py
optimistic_preset
classmethod
¶
Optimistic rate limiting preset.
Prioritizes throughput over stability. Best for: - Interactive/CLI usage - Single-process scenarios - When external retry logic exists
Behavior: - Waits up to 20s for tokens - Light penalty on 429 (15% reduction) - Fast recovery (10% per success) - Never drops below 30% of max_requests
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
max_requests
|
int
|
Maximum requests allowed in the time window. Calculate based on your quota. Default assumes single process using ~80% of a 100 req/min quota. |
80
|
time_window
|
float
|
Time window in seconds for the rate limit. |
60.0
|
Returns:
| Type | Description |
|---|---|
RateLimitConfig
|
RateLimitConfig with optimistic settings. |
Example
Quota of 100 req/min, single process¶
config = RateLimitConfig.optimistic_preset(max_requests=80)
Quota of 200 req/min, want maximum throughput¶
config = RateLimitConfig.optimistic_preset(max_requests=180)
Source code in src/stkai/_config.py
Helper Classes¶
ConfigEntry
dataclass
¶
A configuration field with its resolved value and source.
Represents a single configuration entry with metadata about where the value came from. Used by explain_data() for structured output.
Attributes:
| Name | Type | Description |
|---|---|---|
name |
str
|
The field name (e.g., "request_timeout"). |
value |
Any
|
The resolved value. |
source |
str
|
Where the value came from: - "default": Hardcoded default value - "env:VAR_NAME": Environment variable - "CLI": StackSpot CLI (oscli) - "configure": Set via STKAI.configure() |
Example
entry = ConfigEntry("request_timeout", 60, "configure") entry.name 'request_timeout' entry.value 60 entry.source 'configure' entry.formatted_value '60'
Source code in src/stkai/_config.py
Error Classes¶
ConfigEnvVarError ¶
Bases: ValueError
Raised when an environment variable has an invalid value.
Source code in src/stkai/_config.py
ConfigValidationError ¶
Bases: ValueError
Raised when a configuration value fails validation.