Production Best Practices
This guide covers the SDK settings and product features that matter when an instrumented agent goes to production. Examples use the Python SDK (ants-platform).
Configure once from the environment
Create the client once at process startup and call get_client() everywhere else. Keep all settings in environment variables so each deployment can differ without code changes.
| Variable | Purpose | Default |
|---|---|---|
ANTS_PLATFORM_PUBLIC_KEY, ANTS_PLATFORM_SECRET_KEY | Project API key pair | none |
ANTS_PLATFORM_HOST | URL of your ANTS Platform app | Set it explicitly |
ANTS_PLATFORM_TRACING_ENVIRONMENT | Environment name on every trace, for example production or staging | default |
ANTS_PLATFORM_RELEASE | Release or commit of your application | not set |
ANTS_PLATFORM_SAMPLE_RATE | Share of traces to send, from 0.0 to 1.0 | 1.0 |
ANTS_PLATFORM_FLUSH_AT | Spans per batch | 512 |
ANTS_PLATFORM_FLUSH_INTERVAL | Seconds between batch sends | 5 |
ANTS_PLATFORM_TIMEOUT | Timeout in seconds for SDK API requests | 5 |
ANTS_PLATFORM_TRACING_ENABLED | Set to false to stop sending traces | true |
ANTS_PLATFORM_DEBUG | Verbose SDK logs | false |
Each variable has a matching constructor argument, such as environment=, release=, sample_rate=, flush_at=, flush_interval=, timeout=, tracing_enabled= and debug=.
Environment names must be lowercase letters, digits, hyphens or underscores and must not start with ants-platform.
Use a separate API key pair per service and environment, so you can rotate or revoke one without affecting the others. See API Keys.
Production checklist
Name every agent
The outermost observation of every trace needs an agent_name, or the SDK raises ValueError: agent_name is required. Use a stable name per agent, because the name identifies the agent across traces. Set version= on observations or traces when you ship a new agent version.
Flush on shutdown
The SDK sends data in background batches and flushes automatically when a normal Python process exits. Call flush() yourself where that does not happen, such as at the end of a serverless handler or a scheduled job:
In a long-running worker with its own shutdown hook, call get_client().shutdown() there.
Control volume
Set ANTS_PLATFORM_SAMPLE_RATE to send a fraction of traces from high-traffic services. Sampling is per trace, so a sampled trace keeps all its observations.
@observe() captures function arguments and return values by default. For functions with large or sensitive payloads, turn this off per function or globally:
To turn it off for all decorated functions, set ANTS_PLATFORM_OBSERVE_DECORATOR_IO_CAPTURE_ENABLED=false.
Mask sensitive data
A mask function runs on every input, output and metadata value before it leaves your process:
To detect PII, PCI and PHI in traffic that is already traced, see PII Detection and AI Guardrails. How long trace data is kept is set under Organization Settings > Data Retention, for users with access to it.
Serve prompts with a fallback
If you use Prompt Management, fetch the production label and pass a fallback so a fetch failure never breaks a request. Fetched prompts are cached in the process (60 seconds by default).
Passing ants_platform_prompt=prompt links the generation to the prompt version that produced it.
Verify the deployment
Run get_client().auth_check() once in a deploy smoke test, not in request handlers; it is a blocking network call. Then send one request and confirm the trace appears in Discover AI > Tracing with the expected environment and release.
The first agent observation in each process looks up the project through the API. If the host is unreachable or the keys are invalid at that moment, opening the observation raises an error in your code. This lookup also runs when tracing is disabled. Check credentials and network access to the host before you send production traffic.
Monitoring in production
| Question | Where to look |
|---|---|
| What did a specific request do? | Discover AI > Tracing, filtered by environment, user, tags or level |
| How did a conversation go? | Discover AI > Sessions |
| What are we spending, and on which models? | Gauge AI > Cost Dashboard and Cost Performance Metrics |
| Where is latency coming from? | Gauge AI > Latency Dashboard and Latency & Analytics |
| How is usage trending? | Gauge AI > AI Usage |
| Could a cheaper model do the job? | Gauge AI > AI Optimizer (AI Optimizer) |
| Are answers good? | Scores from users, annotators and LLM-as-a-Judge evaluators running on incoming traces |
For views specific to your team, build Custom Dashboards from traces, observations and scores. To move trace data into your own systems, use Data Exports or the Public API.
Alerts and spend limits
Tracing does not send alerts on error rate, latency or cost thresholds. Watch those in the dashboards above, or export the data to your own monitoring system.
What is available today:
- Automations run when a prompt version is created, updated or deleted, and send a webhook or a Slack message. Use them to notify a channel or trigger a deployment when a prompt label changes. See Automations.
- Budget AI applies rate limits and USD budgets to LLM traffic routed through it, under Budget AI > Budgets & Limits. A budget either stops requests or only records threshold crossings when it is reached. See Budgets & Limits.
- Governance surfaces policy violations in Governance > AI Violations and the Risk Dashboard. See AI Governance.
Scaling
Scaling, load balancing and failover are handled by your own deployment platform. The SDK needs nothing special: every instance reads the same environment variables and sends to the same project. Make sure each instance flushes on shutdown so spans are not lost when it is stopped.
Troubleshooting
| Symptom | Likely cause |
|---|---|
| Traces missing from serverless functions | No flush() before the handler returns |
ValueError: agent_name is required | A root observation, @observe() function or OpenAI drop-in call ran outside an agent observation |
| Fewer traces than requests | ANTS_PLATFORM_SAMPLE_RATE is below 1.0 |
| Production and staging traces mixed together | ANTS_PLATFORM_TRACING_ENVIRONMENT not set per deployment |
| Generations show no cost | The model has no price under Settings > Models; see Models & Pricing |
For deeper investigation, see Debugging AI Agents.
Next steps
- Debugging AI Agents
- Cost Optimization
- Members & Roles to control who can see trace data
- Python SDK reference