Quickstart
OpenTools provides ready-made toolsets (such as Trading) that return consistent, structured outputs across models and frameworks.
In this quickstart, you’ll build a minimal agent that connects to your Alpaca account and returns account information using OpenAI.
Get started
1. Install the SDK
Open a terminal, create a new project folder, set up a virtual environment, and install the required dependencies.
Using uv (recommended)
mkdir my_agent
cd my_agent
uv venv
uv pip install opentools-sdk openai python-dotenv
Using pip
mkdir my_agent
cd my_agent
python -m venv .venv
source .venv/bin/activate
pip install opentools-sdk openai python-dotenv
Using a virtual environment ensures this demo stays isolated from your other projects.
2. Add your API keys
OpenTools reads credentials from environment variables.
This quickstart uses Alpaca for trading and OpenAI as the model provider.
OpenAI API key
If you already have an OpenAI API key, add it to your environment.
Steps:
- Go to the OpenAI dashboard (API keys section)
- Click Create new secret key
- Copy the key and store it somewhere safe
If you already export OPENAI_API_KEY globally, you can omit it from the .env file.
Alpaca API key
Steps:
- Create an Alpaca account (paper trading requires no funding)
- From the dashboard homepage, find Your API Keys
- Click Generate New Keys
- Copy:
- Key ID
- Secret Key
Note
Alpaca only shows the secret key once. If you lose it, you must generate a new key pair.
Create a .env file
This quickstart uses paper trading by default.
OpenTools does not store credentials or manage OAuth. All keys remain local.
Create a file named .env in the same directory as main.py:
OPENAI_API_KEY="your_openai_api_key"
ALPACA_KEY="your_alpaca_key_id"
ALPACA_SECRET="your_alpaca_secret_key"
3. Run your first tool call
You’re about to run a small tool loop:
- The LLM decides which trading tool to call
- OpenTools executes the tool
- The LLM summarises the result
This example uses paper trading and minimal output.
Create main.py
import asyncio
import os
from dotenv import load_dotenv
from openai import AsyncOpenAI
from opentools import trading
from opentools.adapters.models.openai import run_with_tools
async def main() -> None:
load_dotenv()
client = AsyncOpenAI(api_key=os.environ["OPENAI_API_KEY"])
service = trading.alpaca(
api_key=os.environ["ALPACA_KEY"],
api_secret=os.environ["ALPACA_SECRET"],
model="openai",
paper=True,
minimal=True,
)
prompt = "Show my account summary and list any open positions."
result = await run_with_tools(
client=client,
model="gpt-4.1-mini",
service=service,
user_prompt=prompt,
)
print(result)
if __name__ == "__main__":
asyncio.run(main())
Run the script
python main.py
If the model does not call tools, make the prompt more explicit, for example:
Get my accountList positionsShow recent orders
Metadata
Release files for opentools-sdk 0.1.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 |
|---|---|---|---|---|
| opentools_sdk-0.1.0.tar.gz | 43.4 kB | Without provenance | Details for opentools_sdk-0.1.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| opentools_sdk-0.1.0-py3-none-any.whl | Python 3 | none | any | Details for opentools_sdk-0.1.0-py3-none-any.whl |
Total release size: 108.7 kB
Release files / opentools_sdk-0.1.0.tar.gz
| Download URL | opentools_sdk-0.1.0.tar.gz |
|---|---|
| Size | 43.4 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
938cce092543184829e7aaf62eca3c964608c847a2dfaa778a5a50cd12061679
|
|
BLAKE2b-256 checksum How to use checksums |
b9c13cf9b05e70d41e6f8d532878ed23f216818193f4e2e09aa11f56d29f3512
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.12.11
|
Release files / opentools_sdk-0.1.0-py3-none-any.whl
| Download URL | opentools_sdk-0.1.0-py3-none-any.whl |
|---|---|
| Size | 65.3 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
fafb5376dbf48c721e4e84e56de6f1f26b1a8adce5a972eca2cc66e5451121ec
|
|
BLAKE2b-256 checksum How to use checksums |
2f8f20bbb31ada87479c8200f5bc41284ca93edb17167a2627c1cda448b70456
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.12.11
|
Security for opentools-sdk 0.1.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.
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.