API Key Management

You will need an API key to authenticate your requests to the Mechanix API. To obtain your API key, navigate to the dashboard and copy the value beginning with mec-.

Store the API key in a secure area, such as an .env file. Exporting the API key as an environment variable enables it to be utilized in code:

Use the export command to set the MECHANIX_API_KEY environment variable:

export MECHANIX_API_KEY="your_api_key_here"

First API Request

With your API key exported, you can make your first request using either the REST API directly or the Python SDK. Here, we’ll query the Web Search tool to know what OpenAI’s ‘o3’ model is.

Install the Mechanix Python SDK using pip:

pip install --pre mechanix
# Note: --pre installs prereleases. Ensure the version is at least 0.1.0a6.

Make your first API request:

from mechanix import Mechanix

# The MECHANIX_API_KEY environment variable is automatically retrieved.
# Alternatively, you can explicitly pass it using the `api_key` argument.
mec = Mechanix()

# Perform a web search and request an LLM-generated answer
response = mec.tools.search_web(query="What is OpenAI's 'o3' model?", llm_answer=True)

print(response.data.llm.answer)
# Sample Output (may vary):
# OpenAI's 'o3' model is a large language model designed for complex tasks...

Next Steps

You’ve now made your first Mechanix API request! 🎉

Explore the following resources to continue learning: