Get started
Install the SDK
Open your terminal. We’re going to create a folder called my_agent, set up a virtual environment, and install the minimal dependencies.
Add your API keys to your .env file
OpenTools reads credentials from environment variables. For this quickstart we’ll use Alpaca because of its strong capabilities and easy setup.
Model API key
OpenAI API key, just add it to your newly-created .env file.- Navigate to the OpenAI dashboard (API keys section)
- Click Create new secret key
- Copy the key and store it somewhere safe (OpenAI recommends a secure place like your
.zshrcbut ensure to add it to your .env file)
.env file and python-dotenv.If you already export
OPENAI_API_KEY globally, you can omit it from .env.Alpaca API key
.env section below.- Create an Alpaca account (no funding required for paper trading)
- In the dashboard homepage, find Your API Keys
- Click Generate New Keys
- Copy:
- Key ID
- Secret Key (shown only once)
Create a .env file
This quickstart uses paper trading by default and never places live trades unless you explicitly enable it. OpenTools does not store keys or manage OAuth. All credentials stay on your machine and are only used when tools are called.
In the same folder as main.py, create a file named .env:
Run your first tool call
You’re about to run a small tool loop: the LLM decides which trading tool to call, OpenTools executes it, and the LLM summarises the result.
Create a main.py
Create a file named main.py and paste the following code:
The code above will add the tools automatically to the LLM context and use a loop to relay tool responses. The tools output structured schemas to ensure interpretability is maximised and relay the information accurately - this has been tested with LLMs as small as 7 billion parameters with clear, correct results.
Run your code
If the model responds without calling tools, ensure you structure yours prompts directly around the tool,
here are some examples: “Get my account”, “List positions”, or “Show recent orders”.
KeyError, one of your environment variables is missing
or your .env file is not in the same directory as main.py.What just happened
When you ran main.py, you gave the model a set of tool definitions from the Trading module. The model decided whether to call any tools. OpenTools executed those calls against Alpaca, then fed the results back to the model until it returned your final answer.
This resulted in token-efficient output for your agent and guaranteed structure if calling the same tool again since intperpretability is standardised for model performance. Learn more about our capabilities and project structuring in the cards below.
Modules
Models
Next steps
This quickstart uses OpenAI directly. If you want a framework-managed agent loop, using PydanticAI for example, head to Frameworks or navigate by clicking on the card below.