ANTS Platform Python SDK
Tracing, cost and governance for AI agents.
Installation
pip install ants-platform-sdk
With the OpenAI integration:
pip install "ants-platform-sdk[openai]"
From 3.7.0 the package is published as ants-platform-sdk; the import stays import ants_platform. If you used the old ants-platform package, remove it first:
pip uninstall ants-platform && pip install ants-platform-sdk
Quick start
1. Set your keys
Create an API key pair in ANTS Platform under Project Settings > API Keys, then set:
export ANTS_PLATFORM_PUBLIC_KEY="pk-ap-..."
export ANTS_PLATFORM_SECRET_KEY="sk-ap-..."
export ANTS_PLATFORM_HOST="https://<your-ants-host>"
Always set the host: use the address your administrator gives you.
2. Trace an agent and its OpenAI calls
from ants_platform import AntsPlatform
from ants_platform.openai import openai # traced drop-in for the OpenAI SDK
ants = AntsPlatform() # reads the ANTS_PLATFORM_* variables
def answer(question: str) -> str:
with ants.start_as_current_span(
name="support-request",
agent_name="support_agent",
input={"question": question},
) as span:
ants.update_current_trace(user_id="user-123", session_id="session-1")
response = openai.chat.completions.create(
model="gpt-4o-mini",
messages=[{"role": "user", "content": question}],
)
text = response.choices[0].message.content
span.update(output={"answer": text})
return text
print(answer("How do I reset my password?"))
ants.flush() # send buffered traces before a short script exits
The outermost span needs an agent_name; everything inside it is attributed to that agent. The OpenAI call is recorded as a generation with model, tokens, cost and latency.
3. Trace your own steps
Decorate functions with @observe to record them as steps inside the agent's trace:
from ants_platform import AntsPlatform, observe
ants = AntsPlatform()
@observe()
def search_kb(query: str) -> list[str]:
return ["Open Settings > Security > Reset password"]
@observe(as_type="tool")
def create_ticket(summary: str) -> str:
return "TCK-1042"
with ants.start_as_current_span(name="support-request", agent_name="support_agent"):
articles = search_kb("reset password")
ticket = create_ticket("Password reset help")
ants.flush()
4. Calling models through the Budget AI gateway
Point the traced OpenAI client at your Budget AI gateway with a gateway key. The gateway enforces budgets and limits, and the call is recorded once, inside your agent's trace:
from ants_platform.openai import openai
client = openai.OpenAI(
base_url="https://<your-gateway-host>/v1",
api_key="sk-ants-...",
)
with ants.start_as_current_span(name="support-request", agent_name="support_agent"):
client.chat.completions.create(
model="<model-group>",
messages=[{"role": "user", "content": "Hello"}],
)
Learn more
- Quick start: from a new account to your first trace
- Understanding AI agents: how traces are attributed to agents
- Authentication: API keys and hosts
- Full documentation
License
MIT
Metadata
Release files for ants-platform-sdk 3.8.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| ants_platform_sdk-3.8.0.tar.gz | 315.4 kB | With provenance | Details for ants_platform_sdk-3.8.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| ants_platform_sdk-3.8.0-py3-none-any.whl | Python 3 | none | any | Details for ants_platform_sdk-3.8.0-py3-none-any.whl |
Total release size: 687.6 kB
Release files / ants_platform_sdk-3.8.0.tar.gz
| Download URL | ants_platform_sdk-3.8.0.tar.gz |
|---|---|
| Size | 315.4 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
34947f9ae654ee6ffbed8e84a49cc7ae8ff9712ba0f1a7d59c8ad031c6f9978e
|
|
BLAKE2b-256 checksum How to use checksums |
712d73f895b3d251a958ecbf3143ff01016a166e6ca15c23e77f76748a0e81ac
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 20, 2026.
Transparency logRelease files / ants_platform_sdk-3.8.0-py3-none-any.whl
| Download URL | ants_platform_sdk-3.8.0-py3-none-any.whl |
|---|---|
| Size | 372.2 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
860bc4966691c1ef39084c92ec972ef42a0dc41f8a766ead6eabb1b7f5ddfefb
|
|
BLAKE2b-256 checksum How to use checksums |
d50818328f4f32da80792a495ccf91cfd50e8d8d6805c69dfade42f559e00ab0
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 20, 2026.
Transparency logSecurity for ants-platform-sdk 3.8.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
Full provenance
Both files in this release have been uploaded with provenance metadata.
Attestation for ants_platform_sdk-3.8.0.tar.gz
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 20, 2026.
Transparency logA note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.