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"
Use the export
command to set the MECHANIX_API_KEY
environment variable:
export MECHANIX_API_KEY="your_api_key_here"
Use PowerShell to set the MECHANIX_API_KEY
environment variable:
$env: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...
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...
Install the Mechanix JavaScript SDK using npm
:
Make your first API request:
import Mechanix from "mechanix";
const client = new Mechanix({ apiKey: "YOUR_MECHANIX_API_KEY" });
async function main() {
const response = await client.tools.searchWeb({
query: "What is OpenAI's 'o3' model?",
llm_answer: true,
});
console.log(response.data.llm.answer);
}
main();
Here’s how you can make a request using cURL
:
curl -X POST "https://api.mechanix.tools/v1/tools/search_web" \
-H "Content-Type: application/json" \
-H "X-API-Key: YOUR_MECHANIX_API_KEY" \
-d '{"query": "What is OpenAI'\''s '\''o3'\'' model?", "llm_answer": true}'
Sample Output (may vary):
{
"data": {
"results": [
...
]
"llm": {
"answer": "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: