GET STARTED
From key to first response.
Make your first Tokely request in three steps.
01 / Create an API key
Open Sign in and create an account or sign in to your existing account. In Dashboard → API keys, create a key and copy its secret when it is revealed. Keep it on your server, outside your source code.
Check your balance in the dashboard. Your account balance and API key budget must cover the request.
02 / Set up your environment
Store your key in an environment variable using the command for your terminal. Replace the placeholder with the complete secret from your dashboard.
export TOKELY_API_KEY="<YOUR_TOKELY_API_KEY>"Install your SDK
Python needs Python 3 and pip. JavaScript needs a supported Node.js version and npm. Use the SDK installation command for your chosen language. For cURL, no SDK is needed.
python3 -m pip install openai03 / Send a request
This example uses gpt-4o-mini with Chat Completions. Change the model ID to another available model that supports this endpoint.
curl https://api.tokely.me/v1/chat/completions \
-H "Authorization: Bearer $TOKELY_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "gpt-4o-mini",
"messages": [{"role": "user", "content": "Hello, Tokely!"}],
"max_tokens": 256
}'Run your example
For Python, save the Python example above as hello.py. For JavaScript, save the JavaScript example as hello.mjs so Node.js treats it as an ES module. Run it from the directory where you installed the SDK. On Windows, the py launcher can replace python3 if installed. The cURL example runs directly in a macOS/Linux terminal; Python and JavaScript examples also work with the PowerShell environment setting.
Set TOKELY_API_KEY in the same terminal before running the file. Replace the placeholder with your own key, including its sk- prefix. Environment variables are not automatically shared between terminal windows.
python3 hello.pyKnow when it worked
Python and JavaScript print the generated text, for example: Hello! How can I help you today? The exact wording changes between requests. cURL prints the JSON response.
This shortened JSON illustrates the shape of a successful response; IDs, content and usage values are examples. Read choices[0].message.content for your answer.
{
"object": "chat.completion",
"model": "gpt-4o-mini",
"choices": [
{
"index": 0,
"message": {
"role": "assistant",
"content": "Hello! How can I help you today?"
},
"finish_reason": "stop"
}
],
"usage": {
"prompt_tokens": 12,
"completion_tokens": 10,
"total_tokens": 22
}
}Make it your own
Read generated text from choices[0].message.content and token counts from usage. Next, explore model selection, streaming or function calling.