Skip to main content

Stacklink Python SDK

Stacklink supplies executable, governed tools to an agent harness. The selected harness owns the model call, tool loop, and final answer.

Install the public package with the harness extra you use:

uv add 'stacklink-sdk[openai-agents]'

or:

uv add 'stacklink-sdk[claude-agent]'

The complete guides and certified recipes live at docs.stacklink.in. PyPI is the package delivery system, not the primary documentation surface. Stacklink does not display registry download badges in its product or documentation.

Certified agent harnesses

Harness Stacklink adapter
OpenAI Agents SDK create_stacklink_openai_agents_tools(session)
Claude Agent SDK create_stacklink_claude_agent_tool_config(session)

Both start with one explicit Stacklink session:

import os
from stacklink import Stacklink

stacklink = Stacklink(
    api_key=os.environ['STACKLINK_API_KEY'],
    base_url=os.getenv('STACKLINK_BASE_URL', 'https://api.stacklink.in'),
)
session = stacklink.sessions.create_bound({
    'externalTenantId': 'acme',
    'externalUserId': 'user_123',
    'modelSurface': {'mode': 'router'},
})

try:
    # Pass the selected Stacklink adapter output to your agent harness.
    pass
finally:
    session.close()

The complete OpenAI Agents and Claude Agent examples shown by the Stacklink Overview are generated from the executable files under examples/sdk/. The dashboard, documentation, and certification tests all read those same files.

The raw OpenAI with_stacklink_memory helper remains a separate Memory integration. It is not the agent-tool integration and is not part of basic Overview onboarding.

Environment variables are STACKLINK_API_KEY, optional STACKLINK_BASE_URL, and the model-provider credentials required by the selected harness. The SDK is proprietary and is provided under the applicable Stacklink agreement.

Accepted operations, approvals and retries

An execution response can be pending. Keep its executionKind, executionId, session ID and retry key in your application. Read or wait for that operation using the existing execution APIs. A lost connection does not submit a second action, and closing the application session can remove the authority required to execute pending work.

Retry keys are case-sensitive and accept up to 240 characters. Tool and batch requests have separate key namespaces. Reuse a key only for the exact same request in the same SDK session. Changed inputs return 409 idempotency_key_reused; an expired stored result returns 410 execution_result_expired. Neither response authorizes submitting the write again.

For waiting_for_approval, read the shared request using client.approvals and platform_approvals:read. A decision also needs platform_approvals:manage and the authority required by that request. A server key alone cannot approve on behalf of a company person; eligible customer confirmation uses the verified session and its scoped grant. Keep the API key on your backend. A pending action must not be labelled completed. provider_execution_result_unknown means an external write may have happened; inspect the provider before considering another action.

Use execution cancellation for an explicit Stop request. Losing a stream only stops observation. Vercel and LangChain adapters forward their supported abort signal; other adapters keep the structured operation identity available for explicit cancellation. MCP progress reports actual stages, not invented percentages.

Streaming has a total observation deadline and a separate inactivity timeout. A timeout raises sdk_stream_timeout without repeating the action; use its original operation ID to resume observation. Stream responses are limited to 8 MiB, including JSON responses to streaming requests. The synchronous client keeps blocking reads in a bounded reader and releases the response when that read finishes or reaches its inactivity timeout. Custom transports must honor the timeout passed to them. MCP calls return once all matching responses arrive, even if the server keeps the stream open.

Hosted Bots (0.3.2)

Bots are saved, published agents with project-scoped configuration and durable runs. Use a server-held project API key with bots:manage to create/update/publish, and bots:run to invoke. Supply a session established from your authenticated customer; input variables do not grant identity or access. Both SDKs expose run status, replayable events, cancellation and callback delivery recovery. A callback failure does not rerun the model.

bot = stacklink.bots.get(bot_id)
run = stacklink.bots.run(bot_id, session_id=session.id, message="Where is my order?", variables={"orderNumber": "4821"})
for event in stacklink.bots.stream(bot_id, run["id"]):
    print(event)
result = stacklink.bots.get_run(bot_id, run["id"])
print(result["output"] or result["finalText"])

The async client provides the same operations with await and async for.

Reuse the returned conversationId for the next message. Preserve the last event sequence to resume observation. Published invocations are available through the existing session MCP endpoint using STACKLINK_BOTS; no separate server per bot is needed.

Shared approvals (0.3.3)

client.approvals lists and retrieves approvals for an authorized session, submits a permitted decision or customer correction, and observes reconnectable approval events. A project key represents an application; it cannot substitute for a required human company approver. as_customer=True derives the customer from the authenticated session and still requires a scoped customer grant. Continue observing the original execution after deciding; do not resubmit the action.

All enabled notification channels use the same stored request. Decision, notification delivery and execution have separate states. See the approval guide for request and lifecycle details.

When project settings require Workbench code approval, a foreground code/bash call returns waiting_for_approval, approvalRequestId, and its original execution ID immediately. No runtime sandbox is allocated for that wait. After the authorized person decides, observe the original execution; do not submit the code again.

Server-side customer grant management (0.3.5): get_customer_grant, save_customer_grant, and remove_customer_grant operate on an authenticated customer session. Save exact tool keys and resource restrictions with the returned settings revision. The server supplies identity from the session; callers cannot choose another customer in the request body. These methods never grant company approval or bypass connected-account access.

Metadata

Release files for stacklink-sdk 0.3.7

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for stacklink-sdk 0.3.7
File Size Uploaded Provenance
stacklink_sdk-0.3.7.tar.gz 58.7 kB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for stacklink-sdk 0.3.7
File Interpreter ABI Platform
stacklink_sdk-0.3.7-py3-none-any.whl Python 3 none any Details

Total release size: 105.7 kB

Security for stacklink-sdk 0.3.7

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.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A 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.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page