Hard-coded API keys and timeouts work for prototypes. Production needs environment-specific configuration, secrets management, and the ability to change settings without redeploying.
Configuration Hierarchy
Priority (highest → lowest):
1. Environment variables ← deployment-specific overrides
2. Config file (YAML/JSON) ← version-controlled defaults
3. Application defaults ← fallback values in code
Complete Configuration Reference
| Parameter | Env Variable | Default | Description |
|---|---|---|---|
| API Key | CAPTCHAAI_API_KEY |
— | Required. Your CaptchaAI API key |
| Submit URL | CAPTCHAAI_SUBMIT_URL |
https://ocr.captchaai.com/in.php |
Task submit endpoint |
| Poll URL | CAPTCHAAI_POLL_URL |
https://ocr.captchaai.com/res.php |
Result polling endpoint |
| Poll interval | CAPTCHAAI_POLL_INTERVAL |
5 |
Seconds between polling attempts |
| Max poll attempts | CAPTCHAAI_MAX_POLLS |
60 |
Maximum polling attempts before timeout |
| Concurrency | CAPTCHAAI_CONCURRENCY |
10 |
Maximum parallel CAPTCHA tasks |
| Timeout | CAPTCHAAI_TIMEOUT |
300 |
Overall timeout in seconds |
| Proxy | CAPTCHAAI_PROXY |
— | Proxy URL for CAPTCHA solving |
| Callback URL | CAPTCHAAI_CALLBACK_URL |
— | Webhook URL for async results |
| Retry attempts | CAPTCHAAI_RETRIES |
3 |
Retries on transient failures |
| Log level | CAPTCHAAI_LOG_LEVEL |
info |
Logging verbosity |
Configuration Loader
Python
import os
import yaml
from dataclasses import dataclass, field
from pathlib import Path
@dataclass
class CaptchaAIConfig:
api_key: str = ""
submit_url: str = "https://ocr.captchaai.com/in.php"
poll_url: str = "https://ocr.captchaai.com/res.php"
poll_interval: int = 5
max_polls: int = 60
concurrency: int = 10
timeout: int = 300
proxy: str = ""
callback_url: str = ""
retries: int = 3
log_level: str = "info"
@classmethod
def load(cls, config_path=None):
"""Load config: env vars override file, which overrides defaults."""
config = cls()
# Layer 2: Config file
if config_path and Path(config_path).exists():
with open(config_path) as f:
file_config = yaml.safe_load(f) or {}
for key, value in file_config.items():
if hasattr(config, key):
setattr(config, key, value)
# Layer 1: Environment variables (highest priority)
env_map = {
"CAPTCHAAI_API_KEY": "api_key",
"CAPTCHAAI_SUBMIT_URL": "submit_url",
"CAPTCHAAI_POLL_URL": "poll_url",
"CAPTCHAAI_POLL_INTERVAL": "poll_interval",
"CAPTCHAAI_MAX_POLLS": "max_polls",
"CAPTCHAAI_CONCURRENCY": "concurrency",
"CAPTCHAAI_TIMEOUT": "timeout",
"CAPTCHAAI_PROXY": "proxy",
"CAPTCHAAI_CALLBACK_URL": "callback_url",
"CAPTCHAAI_RETRIES": "retries",
"CAPTCHAAI_LOG_LEVEL": "log_level",
}
for env_key, attr_name in env_map.items():
value = os.environ.get(env_key)
if value is not None:
# Cast to correct type
current = getattr(config, attr_name)
if isinstance(current, int):
value = int(value)
setattr(config, attr_name, value)
config.validate()
return config
def validate(self):
if not self.api_key:
raise ValueError("CAPTCHAAI_API_KEY is required")
if self.poll_interval < 1:
raise ValueError("poll_interval must be >= 1")
if self.concurrency < 1:
raise ValueError("concurrency must be >= 1")
# Usage
config = CaptchaAIConfig.load("config/captchaai.yaml")
print(f"Concurrency: {config.concurrency}, Timeout: {config.timeout}s")
JavaScript
const fs = require("fs");
const yaml = require("js-yaml");
const path = require("path");
class CaptchaAIConfig {
static defaults = {
apiKey: "",
submitUrl: "https://ocr.captchaai.com/in.php",
pollUrl: "https://ocr.captchaai.com/res.php",
pollInterval: 5,
maxPolls: 60,
concurrency: 10,
timeout: 300,
proxy: "",
callbackUrl: "",
retries: 3,
logLevel: "info",
};
static envMap = {
CAPTCHAAI_API_KEY: "apiKey",
CAPTCHAAI_SUBMIT_URL: "submitUrl",
CAPTCHAAI_POLL_URL: "pollUrl",
CAPTCHAAI_POLL_INTERVAL: { key: "pollInterval", type: "int" },
CAPTCHAAI_MAX_POLLS: { key: "maxPolls", type: "int" },
CAPTCHAAI_CONCURRENCY: { key: "concurrency", type: "int" },
CAPTCHAAI_TIMEOUT: { key: "timeout", type: "int" },
CAPTCHAAI_PROXY: "proxy",
CAPTCHAAI_CALLBACK_URL: "callbackUrl",
CAPTCHAAI_RETRIES: { key: "retries", type: "int" },
CAPTCHAAI_LOG_LEVEL: "logLevel",
};
static load(configPath = null) {
let config = { ...CaptchaAIConfig.defaults };
// Layer 2: Config file
if (configPath && fs.existsSync(configPath)) {
const ext = path.extname(configPath);
const raw = fs.readFileSync(configPath, "utf8");
const fileConfig = ext === ".json" ? JSON.parse(raw) : yaml.load(raw);
config = { ...config, ...fileConfig };
}
// Layer 1: Environment variables
for (const [envKey, mapping] of Object.entries(CaptchaAIConfig.envMap)) {
const value = process.env[envKey];
if (value !== undefined) {
const attrKey = typeof mapping === "string" ? mapping : mapping.key;
const type = typeof mapping === "string" ? "string" : mapping.type;
config[attrKey] = type === "int" ? parseInt(value, 10) : value;
}
}
CaptchaAIConfig.validate(config);
return config;
}
static validate(config) {
if (!config.apiKey) throw new Error("CAPTCHAAI_API_KEY is required");
if (config.pollInterval < 1) throw new Error("pollInterval must be >= 1");
if (config.concurrency < 1) throw new Error("concurrency must be >= 1");
}
}
// Usage
const config = CaptchaAIConfig.load("config/captchaai.yaml");
console.log(`Concurrency: ${config.concurrency}, Timeout: ${config.timeout}s`);
Per-Environment Config Files
# config/captchaai.yaml — base
api_key: "" # Always set via env var
concurrency: 5
poll_interval: 5
retries: 3
log_level: info
# config/captchaai.production.yaml
concurrency: 20
poll_interval: 3
timeout: 180
log_level: warning
# config/captchaai.staging.yaml
concurrency: 3
poll_interval: 5
timeout: 300
log_level: debug
Secrets Management
Never store API keys in config files or source control.
| Method | Best For | Example |
|---|---|---|
| Environment variables | Containers, CI/CD | export CAPTCHAAI_API_KEY=abc123 |
| AWS Secrets Manager | AWS infrastructure | Fetch at startup; auto-rotation |
| HashiCorp Vault | Multi-cloud, on-prem | Dynamic secrets with TTL |
| Docker secrets | Docker Swarm / Compose | Mounted at /run/secrets/ |
.env file (dev only) |
Local development | dotenv library; .gitignore it |
Docker Compose Example
services:
captcha-worker:
image: captcha-worker:latest
environment:
- CAPTCHAAI_API_KEY=${CAPTCHAAI_API_KEY}
- CAPTCHAAI_CONCURRENCY=15
- CAPTCHAAI_LOG_LEVEL=warning
env_file:
- .env.production
Feature Flags
Toggle capabilities without redeploying:
class FeatureFlags:
def __init__(self):
self.flags = {
"use_callback": os.environ.get("FF_USE_CALLBACK", "false") == "true",
"enable_proxy": os.environ.get("FF_ENABLE_PROXY", "true") == "true",
"max_concurrent": int(os.environ.get("FF_MAX_CONCURRENT", "10")),
}
def is_enabled(self, flag):
return self.flags.get(flag, False)
def get(self, flag, default=None):
return self.flags.get(flag, default)
Troubleshooting
| Issue | Cause | Fix |
|---|---|---|
| API key not loading | Missing env var; wrong variable name | Check echo $CAPTCHAAI_API_KEY; verify spelling |
| Config file ignored | Wrong path or missing YAML library | Verify file exists; install pyyaml / js-yaml |
| Prod using dev settings | Env-specific override not applied | Check env var precedence; verify NODE_ENV / APP_ENV |
| Secrets visible in logs | Config dump includes API key | Mask sensitive fields in log output |
FAQ
Should I use YAML or JSON for config files?
YAML for human-edited files (supports comments). JSON for machine-generated configs or when you want strict parsing.
How often should I rotate API keys?
Rotate immediately if compromised. Schedule rotation every 90 days for compliance. Use secrets managers that support automatic rotation.
Can I change concurrency without restarting?
Yes — read settings from environment variables or a config service on each task batch, not just at startup. This lets you adjust concurrency by updating the env var and sending a reload signal.
Related Articles
- Socks5 Proxy Captchaai Setup Configuration
- Captchaai Teams Multi User Api Key Management
- Captchaai Proxy Configuration Guide
Next Steps
Get your configuration production-ready — start with a CaptchaAI API key and build from the config templates above.
Related guides:
Discussions (0)
Join the conversation
Sign in to share your opinion.
Sign InNo comments yet.