Staso Python SDK
Trace explicitly instrumented agent runs and evaluate proposed tool calls before your code executes them.
Supported launch configuration
- Python 3.11+
- OpenAI Chat Completions or Anthropic Messages
- Synchronous or asynchronous, non-streaming calls
- An explicit
@st.agentroot and@st.toolon executed Python tools - Claude Code and Codex through one-command CLI setup
- Observe plus configured Guard policies in Audit or Enforce mode
Copy-paste launch sample
Use the canonical launch quickstart at https://staso.ai/docs/quickstart/launch. If you have a repository checkout, you can run the pinned copy in examples/launch_quickstart/:
pip install -r examples/launch_quickstart/requirements.txt
requirements.txt pins:
staso[openai]==0.5.15
openai==3.6.0
Set STASO_API_KEY, OPENAI_API_KEY, STASO_AGENT_NAME, STASO_ENVIRONMENT, STASO_WORKSPACE_SLUG, and STASO_SESSION_ID=launch-quickstart-first-trace, then run:
python examples/launch_quickstart/openai_guard_quickstart.py
The sample checks SDK delivery. Onboarding should wait for the dashboard/backend trace query before marking the first trace visible.
OpenAI quickstart
pip install "staso[openai]"
import json
import staso as st
from openai import OpenAI
st.init(api_key="ak_...", agent_name="weather-agent")
client = OpenAI()
TOOLS = [
{
"type": "function",
"function": {
"name": "get_weather",
"description": "Get the weather for a city.",
"parameters": {
"type": "object",
"properties": {"city": {"type": "string"}},
"required": ["city"],
},
},
}
]
@st.tool
def get_weather(city: str) -> dict:
return {"city": city, "temperature_c": 18}
@st.agent
def answer(question: str) -> dict | str:
try:
response = client.chat.completions.create(
model="gpt-4o-mini",
messages=[{"role": "user", "content": question}],
tools=TOOLS,
)
except st.GuardBlocked as blocked:
return f"Blocked: {blocked.reason}"
tool_call = response.choices[0].message.tool_calls[0]
arguments = json.loads(tool_call.function.arguments)
return get_weather(**arguments)
print(answer("What is the weather in London?"))
delivery = st.shutdown(timeout=5)
if not delivery.ok:
raise RuntimeError(f"Trace delivery incomplete: {delivery.last_failure}")
st.init() patches an installed OpenAI SDK. The explicit decorators define the supported trace shape: @st.agent creates the root and @st.tool records the real tool duration, status, input, output, and error.
Guard evaluates tool proposals returned by the patched provider before the normal dispatch loop receives them. An audit finding records a would-block and lets the proposal continue. A block raises st.GuardBlocked.
@st.tool observes a Python function. It does not run Guard by itself. Check a direct tool call explicitly when it needs enforcement:
decision = st.guard("delete_record", {"record_id": "r_42"})
if decision.action == "block":
raise RuntimeError(decision.reason)
delete_record("r_42")
Anthropic
Install staso[anthropic] and use a non-streaming messages.create call under the same explicit decorators. See the Anthropic quickstart.
CLI agents
Connect Claude Code or Codex without changing application code:
pip install staso
staso setup --target claude-code # or codex
See the Claude Code quickstart, Codex quickstart, or CLI reference.
Pricing
Team starts at $39 USD per month for one unit. Each unit includes 10,000 monthly traces and 5,000 monthly Guard LLM-judge evaluations. Team includes unlimited static Guard evaluations.
Choose 1 to 50 Team units. See current pricing and limits for volume discounts and the final signed-in quote, currency, and included capacity. Spans do not add plan usage, but monthly allowances, request limits, and service rate limits still apply.
Capture boundaries
requested_modelrecords the request.modelrecords the provider-resolved ID when the response supplies one, and otherwise falls back to the request.providerrecords the provider identity.usage_available=Truemeans the provider returned usage, including valid zero-token values.Falsemeans the compatibility token counters are not evidence of known zero.- Cost is estimated by the Staso service for recognized models. Unknown usage or an unrecognized model stays unknown instead of becoming
$0. - Five independent categories default on:
request,system_prompt,tool_schema,tool_arguments, andoutput. Configure them withst.init(capture_<category>=...)orSTASO_CAPTURE_<CATEGORY>. - Suppression removes governed values before SDK payload serialization. Enabled content can still be redacted by the backend before storage; these are different states.
- The deprecated
capture_messages=Falsefallback suppressesrequestandsystem_promptonly. Explicit category controls win. - Span delivery is asynchronous. Call
st.flush()to wait for events accepted before that call, orst.shutdown()when the process is done. Both return aDeliveryReport; checkreport.okwhen delivery is required.report.rejectedandreport.last_rejectionexpose local queue drops that happened during automatic decorator cleanup. - Guard fails open when no policy decision is available by default. Use
fail_closed=TrueorSTASO_GUARD_FAIL_CLOSED=truefor calls that must block on explicit degradation.
For a warm serverless worker, flush after each invocation without stopping the shared client:
def handler(event, context):
result = answer(event["question"])
report = st.flush(timeout=2)
if not report.ok:
logger.warning("Staso delivery incomplete: %s", report.last_failure)
return result
Calling st.init() again retires the previous client. Inspect new_client.previous_shutdown_report to verify that drain without making initialization throw by default.
Documentation
- Python decorators
- OpenAI Chat Completions
- Anthropic Messages
- Claude Code
- Codex
- CLI setup
- Guard audit and block
- SDK setup
- Troubleshooting
Python 3.11+ | Apache 2.0
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file staso-0.5.18.tar.gz.
File metadata
- Download URL: staso-0.5.18.tar.gz
- Upload date:
- Size: 130.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via:
twine/7.0.0 CPython/3.13.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
2ef04ba5c86f7de777b24c21f4da45a9ad7f05a7df66f9791d4c30db831d0926
|
|
| MD5 |
57b15866fbdc02583d810369309dd24a
|
|
| BLAKE2b-256 |
12b68b52bd5c41f07528c3b4f1f837df7a35324e112474165564e23feaf1ad6f
|
Provenance
The following attestation bundles were made for staso-0.5.18.tar.gz:
Publisher:
build_deploy_pip_registry.yml on StasoAI/sdk-python
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
staso-0.5.18.tar.gz -
Subject digest:
2ef04ba5c86f7de777b24c21f4da45a9ad7f05a7df66f9791d4c30db831d0926 - Sigstore transparency entry: 2721707117
- Sigstore integration time:
-
Permalink:
StasoAI/sdk-python@e2c3bc0b541718a2fc03a8cba1ee5a29c7a976d4 -
Branch / Tag:
refs/heads/main - Owner: https://github.com/StasoAI
-
Access:
private
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
build_deploy_pip_registry.yml@e2c3bc0b541718a2fc03a8cba1ee5a29c7a976d4 -
Trigger Event:
push
-
Statement type:
File details
Details for the file staso-0.5.18-py3-none-any.whl.
File metadata
- Download URL: staso-0.5.18-py3-none-any.whl
- Upload date:
- Size: 163.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via:
twine/7.0.0 CPython/3.13.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
077c66b6fb95e98ae638793ed4a5970ff0faa50600dff90910e2b05a265e817a
|
|
| MD5 |
7ea8be411d9d36e4324bc81c0436d672
|
|
| BLAKE2b-256 |
d6d40e8f0713f7441030032b7d78f76e2d121f9aa788d9296f6ff8c514b5734e
|
Provenance
The following attestation bundles were made for staso-0.5.18-py3-none-any.whl:
Publisher:
build_deploy_pip_registry.yml on StasoAI/sdk-python
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
staso-0.5.18-py3-none-any.whl -
Subject digest:
077c66b6fb95e98ae638793ed4a5970ff0faa50600dff90910e2b05a265e817a - Sigstore transparency entry: 2721707234
- Sigstore integration time:
-
Permalink:
StasoAI/sdk-python@e2c3bc0b541718a2fc03a8cba1ee5a29c7a976d4 -
Branch / Tag:
refs/heads/main - Owner: https://github.com/StasoAI
-
Access:
private
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
build_deploy_pip_registry.yml@e2c3bc0b541718a2fc03a8cba1ee5a29c7a976d4 -
Trigger Event:
push
-
Statement type: