Files
tilbudgivern/_temp/test_openai_costs_api.sh
alexpolo1 eb03213f16 oprydning
2025-11-26 12:36:27 +00:00

62 lines
1.8 KiB
Bash

#!/bin/bash
# Test script for OpenAI Costs API endpoints
# Usage: ./test_openai_costs_api.sh
API_BASE="http://localhost:4031/api/quotes"
echo "🤖 OpenAI Costs API - Test Script"
echo "=================================="
echo ""
# Colors for output
GREEN='\033[0;32m'
RED='\033[0;31m'
YELLOW='\033[1;33m'
NC='\033[0m' # No Color
# Test 1: OpenAI Stats
echo -e "${YELLOW}Test 1: Get OpenAI Token Usage Stats${NC}"
echo "GET $API_BASE/openai/stats"
echo ""
RESPONSE=$(curl -s "$API_BASE/openai/stats")
echo "$RESPONSE" | python3 -m json.tool 2>/dev/null || echo "$RESPONSE"
echo ""
echo ""
# Test 2: OpenAI Costs (requires OPENAI_ADMIN_KEY)
echo -e "${YELLOW}Test 2: Get OpenAI Costs (last 30 days)${NC}"
echo "GET $API_BASE/openai/costs?daysBack=30"
echo ""
RESPONSE=$(curl -s "$API_BASE/openai/costs?daysBack=30")
echo "$RESPONSE" | python3 -m json.tool 2>/dev/null || echo "$RESPONSE"
echo ""
echo ""
# Test 3: Cost Breakdown
echo -e "${YELLOW}Test 3: Get Cost Breakdown with grouping${NC}"
echo "GET $API_BASE/openai/costs/breakdown?daysBack=30&groupBy=line_item"
echo ""
RESPONSE=$(curl -s "$API_BASE/openai/costs/breakdown?daysBack=30&groupBy=line_item")
echo "$RESPONSE" | python3 -m json.tool 2>/dev/null || echo "$RESPONSE"
echo ""
echo ""
# Test 4: Budget Status
echo -e "${YELLOW}Test 4: Get Budget Status${NC}"
echo "GET $API_BASE/openai/budget/status"
echo ""
RESPONSE=$(curl -s "$API_BASE/openai/budget/status")
echo "$RESPONSE" | python3 -m json.tool 2>/dev/null || echo "$RESPONSE"
echo ""
echo ""
echo -e "${GREEN}✓ All tests completed!${NC}"
echo ""
echo "📝 Notes:"
echo "- Test 2 & 3 require OPENAI_ADMIN_KEY to be set in .env"
echo "- If tests fail, check:"
echo " 1. Backend is running (port 4031)"
echo " 2. .env has OPENAI_ADMIN_KEY configured"
echo " 3. API routes are properly registered"