A simple bash script for making requests to Azure AI APIs with token usage and cost tracking.
- Make single or batch requests to Azure AI endpoints
- Process multiple requests from an input file
- Track token usage and calculate costs
- Display performance metrics (tokens per second, response time)
- Formatted output for easy reading
- Bash shell environment
curlfor making HTTP requestsjqfor parsing JSON responsesbcfor mathematical calculations
./invoke.sh --endpoint_url <url> --api_key <key> [--content <message>] [--input_cost <cost>] [--output_cost <cost>]./invoke.sh --endpoint_url <url> --api_key <key> --input_file <path> [--input_cost <cost>] [--output_cost <cost>]| Parameter | Description | Default |
|---|---|---|
--endpoint_url |
Azure AI API endpoint URL | (Required) |
--api_key |
Your API key | (Required) |
--content |
Message content for single request | "Tell me a story" |
--input_file |
Path to file with one request per line | None |
--input_cost |
Cost per 1,000 input tokens | 0.00013 |
--output_cost |
Cost per 1,000 output tokens | 0.00052 |
# Single request
./invoke.sh --endpoint_url "https://your-endpoint.models.ai.azure.com/chat/completions" --api_key "$API_KEY" --content "Write a haiku about programming" --input_cost 0.00015 --output_cost 0.0006
# Batch processing
./invoke.sh --endpoint_url "https://your-endpoint.models.ai.azure.com/chat/completions" --api_key "$API_KEY" --input_file "requests.txt" --input_cost 0.00015 --output_cost 0.0006The script provides formatted output including:
- Request content
- Full API response
- Token usage statistics
- Cost calculation
- Response time and tokens per second
- Modify the input/output costs to match your specific model pricing
- For batch processing, each line in the input file is treated as a separate request