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 | |
|---|---|---|---|
| opentools_sdk-0.1.0.tar.gz | 43.4 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| opentools_sdk-0.1.0-py3-none-any.whl | Python 3 | none | any | Details |
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
|