Stacklink
Reference

Python SDK

Certified OpenAI Agents SDK and Claude Agent SDK recipes.

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

uv add stacklink-sdk

Create a project API key in Stacklink Overview, keep it in STACKLINK_API_KEY, and use the complete recipe for your harness below. The API key is for code using the SDK; MCP app connections use OAuth instead.

OpenAI Agents SDK

Install the Stacklink SDK with the selected harness:

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

Required environment: STACKLINK_API_KEY, OPENAI_API_KEY, OPENAI_MODEL.

STACKLINK_BASE_URL is optional and defaults to https://api.stacklink.in.

agent.py
import asyncio
import os

from agents import Agent, Runner
from stacklink import Stacklink, create_stacklink_openai_agents_tools


async def main() -> None:
    stacklink = Stacklink(
        api_key=require_environment("STACKLINK_API_KEY"),
        base_url=os.getenv("STACKLINK_BASE_URL", "https://api.stacklink.in"),
    )
    session = stacklink.sessions.create_bound({
        "externalTenantId": "acme",
        "externalUserId": "user_123",
        "metaTools": {"surface": "connector"},
    })
    try:
        agent = Agent(
            name="Stacklink assistant",
            model=require_environment("OPENAI_MODEL"),
            instructions=(
                "Use Stacklink tools to complete the request. "
                "Call STACKLINK_LIST_TOOLKITS before answering."
            ),
            tools=create_stacklink_openai_agents_tools(session),
        )
        result = await Runner.run(
            agent,
            "List the Stacklink toolkits available to me and summarize the result.",
        )
        print(result.final_output)
    finally:
        session.close()


def require_environment(name: str) -> str:
    value = os.getenv(name)
    if not value:
        raise RuntimeError(f"{name} is required.")
    return value


if __name__ == "__main__":
    asyncio.run(main())

Claude Agent SDK

Install the Stacklink SDK with the selected harness:

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

Required environment: STACKLINK_API_KEY, ANTHROPIC_API_KEY, CLAUDE_MODEL.

STACKLINK_BASE_URL is optional and defaults to https://api.stacklink.in.

agent.py
import asyncio
import os

from claude_agent_sdk import ClaudeAgentOptions, ResultMessage, query
from stacklink import Stacklink, create_stacklink_claude_agent_tool_config


async def main() -> None:
    stacklink = Stacklink(
        api_key=require_environment("STACKLINK_API_KEY"),
        base_url=os.getenv("STACKLINK_BASE_URL", "https://api.stacklink.in"),
    )
    session = stacklink.sessions.create_bound({
        "externalTenantId": "acme",
        "externalUserId": "user_123",
        "metaTools": {"surface": "connector"},
    })
    try:
        stacklink_tools = create_stacklink_claude_agent_tool_config(session)
        options = ClaudeAgentOptions(
            model=require_environment("CLAUDE_MODEL"),
            system_prompt=(
                "Use Stacklink tools to complete the request. "
                "Call STACKLINK_LIST_TOOLKITS before answering."
            ),
            tools=[],
            max_turns=6,
            mcp_servers=stacklink_tools["mcp_servers"],
            allowed_tools=stacklink_tools["allowed_tools"],
        )
        final_output = ""
        async for message in query(
            prompt="List the Stacklink toolkits available to me and summarize the result.",
            options=options,
        ):
            if isinstance(message, ResultMessage):
                final_output = message.result or ""
        print(final_output)
    finally:
        session.close()


def require_environment(name: str) -> str:
    value = os.getenv(name)
    if not value:
        raise RuntimeError(f"{name} is required.")
    return value


if __name__ == "__main__":
    asyncio.run(main())

Source of truth

These examples are generated from the same executable files used by Stacklink Overview and release certification. npm and PyPI deliver the packages; this documentation remains the onboarding source of truth.

On this page