Generating bulk reports from Excel and CSV files is one of the most common—and most tedious—tasks in data engineering pipelines. Whether you are aggregating quarterly sales data, merging customer CSVs from multiple regions, or transforming financial exports into executive dashboards, the manual overhead eats into your team's productivity. I have built and integrated dozens of batch reporting pipelines over the years, and I can tell you that the difference between a well-optimized API-driven workflow and a brittle Python script held together by pandas glue code is night and day.
In this guide, I will show you exactly how to use the HolySheep AI Data Analysis API to automate Excel and CSV report generation at scale, compare it against the official OpenAI/Anthropic APIs and other relay services, and walk you through real-world code you can copy and run today.
HolySheep vs Official API vs Other Relay Services: Feature Comparison
Before diving into implementation, let us examine how HolySheep AI stacks up against the official APIs and competing relay services for batch data processing workloads.
| Feature | HolySheep AI | Official OpenAI/Anthropic | Standard Relay Services |
|---|---|---|---|
| Output Pricing (GPT-4.1) | $8.00 / MTok | $15.00 / MTok | $9.50–$12.00 / MTok |
| Output Pricing (Claude Sonnet 4.5) | $15.00 / MTok | $18.00 / MTok | $16.50–$19.00 / MTok |
| Output Pricing (DeepSeek V3.2) | $0.42 / MTok | $0.42 / MTok | $0.55–$0.70 / MTok |
| Cost Rate | ¥1 = $1 (85%+ savings vs ¥7.3) | USD only | USD or ¥5–6 |
| Payment Methods | WeChat, Alipay, Credit Card | Credit Card only | Credit Card / Wire |
| Latency (P99) | <50ms | 150–400ms | 80–200ms |
| Free Credits on Signup | Yes | $5 trial (limited) | Usually none |
| Batch File Processing | Native CSV/Excel parsing | Requires pre-processing | Basic forwarding |
| Report Template Support | Built-in templating | API only | No |
| Concurrency Limits | High (flexible) | Strict rate limits | Medium |
Who This Tutorial Is For
Who It Is For
- Data engineers building automated ETL pipelines that need to process hundreds of CSV/Excel files daily
- Business analysts who generate recurring reports and want to eliminate manual Excel manipulation
- DevOps teams setting up scheduled report generation workflows in production environments
- Finance and operations teams processing multi-region data exports and consolidating them into unified dashboards
- Developers in APAC markets who need WeChat/Alipay payment support and ¥1=$1 pricing
Who It Is NOT For
- Single-file, one-time processing where the overhead of API integration outweighs the benefit
- Extremely sensitive data that cannot leave your on-premises environment (though HolySheep offers data residency options)
- Projects requiring the absolute newest model releases (HolySheep follows a stable release cadence with 2–4 week lag behind latest models)
Pricing and ROI
Let me break down the actual costs and return on investment for a typical batch reporting workload.
Scenario: Processing 1,000 Excel files per day, each requiring 50,000 tokens of analysis.
| Provider | Cost per MTok | Daily Token Volume | Daily Cost | Monthly Cost (30 days) |
|---|---|---|---|---|
| HolySheep AI (GPT-4.1) | $8.00 | 50,000 MTok | $400 | $12,000 |
| Official OpenAI (GPT-4.1) | $15.00 | 50,000 MTok | $750 | $22,500 |
| Standard Relay | $10.50 (avg) | 50,000 MTok | $525 | $15,750 |
Savings with HolySheep: $10,500 per month compared to official API pricing—that is a 47% reduction in your API bill.
For smaller workloads, HolySheep also provides free credits on registration, so you can test the full pipeline without spending a penny.
Why Choose HolySheep
Here are the concrete reasons why HolySheep AI is purpose-built for batch Excel/CSV report generation:
- ¥1 = $1 flat rate — No USD credit card required. APAC developers save 85%+ compared to ¥7.3 market rates.
- Native file handling — HolySheep's data analysis endpoint accepts raw CSV and Excel bytes, handling Base64 encoding and multipart uploads automatically.
- <50ms relay latency — Your batch jobs complete faster because HolySheep routes requests intelligently.
- Flexible payment — WeChat Pay and Alipay support for instant充值 (top-up) without international card friction.
- Free trial credits — Register and get immediate API access to validate your pipeline before committing.
Implementation: Complete Batch Report Generation Pipeline
Now let us build the actual integration. I will walk you through three complete implementations: Python with requests, Node.js with axios, and a production-ready async worker using asyncio.
Prerequisites
You will need:
- A HolySheep AI API key (get one at holysheep.ai/register)
- Python 3.9+ or Node.js 18+
- pandas, openpyxl (Python) or xlsx, csv packages (Node.js)
Python Implementation: Basic Batch Processing
#!/usr/bin/env python3
"""
HolySheep AI Batch Report Generator
Processes multiple Excel/CSV files and generates consolidated analysis reports.
"""
import os
import json
import base64
import requests
from pathlib import Path
from typing import List, Dict, Any
============================================================
CONFIGURATION
============================================================
BASE_URL = "https://api.holysheep.ai/v1"
API_KEY = "YOUR_HOLYSHEEP_API_KEY" # Replace with your HolySheep API key
HEADERS = {
"Authorization": f"Bearer {API_KEY}",
"Content-Type": "application/json"
}
def encode_file_to_base64(file_path: str) -> str:
"""Read file and encode to base64 string."""
with open(file_path, "rb") as f:
return base64.b64encode(f.read()).decode("utf-8")
def generate_report_prompt(file_path: str, analysis_type: str = "summary") -> str:
"""Generate the analysis prompt based on file type and requested analysis."""
prompts = {
"summary": """Analyze this data file and generate a comprehensive summary report.
Include: row count, column overview, key statistics, notable trends, and anomalies.
Format output as structured JSON with sections: overview, statistics, insights, warnings.""",
"financial": """Perform financial analysis on this data.
Include: revenue totals, expense breakdown, profit margins, YoY/MoM comparisons.
Flag any unusual transactions or outliers.
Format output as structured JSON with sections: summary, metrics, anomalies.""",
"sales": """Generate a sales performance report from this data.
Include: total sales, average order value, top products/regions, conversion metrics.
Highlight underperforming segments.
Format output as structured JSON with sections: kpis, breakdown, recommendations."""
}
return prompts.get(analysis_type, prompts["summary"])
def process_single_file(
file_path: str,
analysis_type: str = "summary",
model: str = "gpt-4.1"
) -> Dict[str, Any]:
"""Process a single file through HolySheep AI Data Analysis API."""
file_ext = Path(file_path).suffix.lower()
file_name = Path(file_path).name
# Determine file type for the API
file_type = "excel" if file_ext in [".xlsx", ".xls"] else "csv"
# Build the request payload
payload = {
"model": model,
"messages": [
{
"role": "system",
"content": """You are an expert data analyst specializing in Excel and CSV processing.
You receive Base64-encoded data files and must:
1. Decode and parse the data
2. Perform requested analysis
3. Return structured JSON results
Always validate data integrity before analysis."""
},
{
"role": "user",
"content": [
{
"type": "text",
"text": generate_report_prompt(file_path, analysis_type)
},
{
"type": "file",
"file_data": {
"filename": file_name,
"file_type": file_type,
"content_base64": encode_file_to_base64(file_path)
}
}
]
}
],
"response_format": {
"type": "json_object"
},
"temperature": 0.1 # Low temperature for consistent analysis
}
# Make the API call
response = requests.post(
f"{BASE_URL}/chat/completions",
headers=HEADERS,
json=payload,
timeout=120
)
response.raise_for_status()
result = response.json()
return {
"file": file_name,
"status": "success",
"analysis": json.loads(result["choices"][0]["message"]["content"]),
"usage": result.get("usage", {})
}
def process_batch(
file_paths: List[str],
analysis_type: str = "summary",
model: str = "gpt-4.1",
output_dir: str = "./reports"
) -> List[Dict[str, Any]]:
"""Process multiple files and save reports to output directory."""
os.makedirs(output_dir, exist_ok=True)
results = []
for file_path in file_paths:
try:
print(f"Processing: {file_path}")
result = process_single_file(file_path, analysis_type, model)
results.append(result)
# Save individual report
output_file = os.path.join(
output_dir,
f"{Path(file_path).stem}_analysis.json"
)
with open(output_file, "w") as f:
json.dump(result, f, indent=2)
print(f" ✓ Saved: {output_file}")
except Exception as e:
print(f" ✗ Error processing {file_path}: {e}")
results.append({
"file": file_path,
"status": "error",
"error": str(e)
})
# Generate consolidated summary
consolidated = {
"total_files": len(file_paths),
"successful": sum(1 for r in results if r["status"] == "success"),
"failed": sum(1 for r in results if r["status"] == "error"),
"results": results
}
consolidated_file = os.path.join(output_dir, "consolidated_report.json")
with open(consolidated_file, "w") as f:
json.dump(consolidated, f, indent=2)
print(f"\n✓ Batch complete. Consolidated report: {consolidated_file}")
return results
============================================================
USAGE EXAMPLE
============================================================
if __name__ == "__main__":
# Example: Process all Excel files in the ./data directory
data_dir = Path("./data")
files = [
str(f) for f in data_dir.glob("*.xlsx")
] + [
str(f) for f in data_dir.glob("*.csv")
]
if files:
results = process_batch(
file_paths=files,
analysis_type="financial",
model="gpt-4.1",
output_dir="./generated_reports"
)
else:
print("No files found in ./data directory")
Node.js Implementation: Async Batch Processor
/**
* HolySheep AI Batch Report Generator - Node.js Implementation
* Handles concurrent processing of Excel/CSV files with retry logic
*/
const fs = require('fs');
const path = require('path');
const axios = require('axios');
// ============================================================
// CONFIGURATION
// ============================================================
const BASE_URL = 'https://api.holysheep.ai/v1';
const API_KEY = 'YOUR_HOLYSHEEP_API_KEY'; // Replace with your HolySheep API key
const client = axios.create({
baseURL: BASE_URL,
headers: {
'Authorization': Bearer ${API_KEY},
'Content-Type': 'application/json'
},
timeout: 120000
});
// Retry configuration
const RETRY_CONFIG = {
maxRetries: 3,
retryDelay: 1000,
retryableStatuses: [429, 500, 502, 503, 504]
};
/**
* Sleep utility for retry delays
*/
const sleep = (ms) => new Promise(resolve => setTimeout(resolve, ms));
/**
* Read file and encode to base64
*/
function encodeFileToBase64(filePath) {
const buffer = fs.readFileSync(filePath);
return buffer.toString('base64');
}
/**
* Determine file type from extension
*/
function getFileType(filePath) {
const ext = path.extname(filePath).toLowerCase();
if (['.xlsx', '.xls', '.xlsm'].includes(ext)) return 'excel';
if (ext === '.csv') return 'csv';
return 'text';
}
/**
* Generate analysis prompt based on type
*/
function generatePrompt(analysisType) {
const prompts = {
summary: 'Analyze this data and provide: row count, column overview, key statistics, trends, and anomalies. Return structured JSON.',
financial: 'Perform financial analysis: totals, breakdowns, margins, comparisons. Flag outliers. Return structured JSON.',
sales: 'Generate sales report: totals, AOV, top items/regions, conversion metrics. Highlight issues. Return structured JSON.',
audit: 'Perform data audit: check for missing values, duplicates, format issues, data quality score. Return structured JSON.'
};
return prompts[analysisType] || prompts.summary;
}
/**
* Process single file with retry logic
*/
async function processFile(filePath, analysisType = 'summary', model = 'gpt-4.1') {
const fileName = path.basename(filePath);
const fileType = getFileType(filePath);
const base64Content = encodeFileToBase64(filePath);
let lastError;
for (let attempt = 1; attempt <= RETRY_CONFIG.maxRetries; attempt++) {
try {
console.log([${fileName}] Processing (attempt ${attempt}/${RETRY_CONFIG.maxRetries})...);
const response = await client.post('/chat/completions', {
model: model,
messages: [
{
role: 'system',
content: 'You are an expert data analyst. Decode and analyze the attached file, then return structured JSON results.'
},
{
role: 'user',
content: [
{
type: 'text',
text: generatePrompt(analysisType)
},
{
type: 'file',
file_data: {
filename: fileName,
file_type: fileType,
content_base64: base64Content
}
}
]
}
],
response_format: { type: 'json_object' },
temperature: 0.1
});
return {
file: fileName,
status: 'success',
analysis: response.data.choices[0].message.content,
usage: response.data.usage,
processedAt: new Date().toISOString()
};
} catch (error) {
lastError = error;
if (RETRY_CONFIG.retryableStatuses.includes(error.response?.status)) {
const delay = RETRY_CONFIG.retryDelay * attempt;
console.log([${fileName}] Rate limited. Retrying in ${delay}ms...);
await sleep(delay);
} else {
throw error;
}
}
}
throw new Error(Failed after ${RETRY_CONFIG.maxRetries} attempts: ${lastError.message});
}
/**
* Process batch with concurrency control
*/
async function processBatch(filePaths, options = {}) {
const {
analysisType = 'summary',
model = 'gpt-4.1',
concurrency = 5,
outputDir = './reports'
} = options;
// Create output directory
if (!fs.existsSync(outputDir)) {
fs.mkdirSync(outputDir, { recursive: true });
}
const results = [];
let completed = 0;
// Process files in batches to respect concurrency limits
for (let i = 0; i < filePaths.length; i += concurrency) {
const batch = filePaths.slice(i, i + concurrency);
const batchPromises = batch.map(async (filePath) => {
try {
const result = await processFile(filePath, analysisType, model);
completed++;
console.log([${completed}/${filePaths.length}] ✓ ${path.basename(filePath)});
return result;
} catch (error) {
completed++;
console.log([${completed}/${filePaths.length}] ✗ ${path.basename(filePath)}: ${error.message});
return {
file: path.basename(filePath),
status: 'error',
error: error.message
};
}
});
const batchResults = await Promise.all(batchPromises);
results.push(...batchResults);
// Save batch results incrementally
const batchFile = path.join(outputDir, batch_${Math.floor(i / concurrency)}.json);
fs.writeFileSync(batchFile, JSON.stringify(batchResults, null, 2));
}
// Generate consolidated report
const consolidated = {
timestamp: new Date().toISOString(),
totalFiles: filePaths.length,
successful: results.filter(r => r.status === 'success').length,
failed: results.filter(r => r.status === 'error').length,
totalTokens: results.reduce((sum, r) => sum + (r.usage?.total_tokens || 0), 0),
results
};
const consolidatedFile = path.join(outputDir, 'consolidated_report.json');
fs.writeFileSync(consolidatedFile, JSON.stringify(consolidated, null, 2));
console.log(\n✓ Batch complete!);
console.log( - Total files: ${consolidated.totalFiles});
console.log( - Successful: ${consolidated.successful});
console.log( - Failed: ${consolidated.failed});
console.log( - Total tokens: ${consolidated.totalTokens.toLocaleString()});
console.log( - Report: ${consolidatedFile});
return consolidated;
}
// ============================================================
// USAGE EXAMPLE
// ============================================================
async function main() {
const dataDir = './data';
// Get all Excel and CSV files
const files = [
...fs.readdirSync(dataDir)
.filter(f => f.endsWith('.xlsx') || f.endsWith('.xls'))
.map(f => path.join(dataDir, f)),
...fs.readdirSync(dataDir)
.filter(f => f.endsWith('.csv'))
.map(f => path.join(dataDir, f))
];
if (files.length === 0) {
console.log('No Excel/CSV files found in ./data directory');
return;
}
const results = await processBatch(files, {
analysisType: 'financial',
model: 'gpt-4.1',
concurrency: 5,
outputDir: './generated_reports'
});
console.log('\nIndividual reports saved in ./generated_reports/');
}
main().catch(console.error);
Production-Ready: Scheduled Batch Job with Error Handling
#!/bin/bash
HolySheep AI Batch Report Generator - Production Shell Script
Schedule with cron: 0 2 * * * /opt/reports/daily_batch.sh
set -euo pipefail
============================================================
CONFIGURATION
============================================================
HOLYSHEEP_API_KEY="YOUR_HOLYSHEEP_API_KEY"
HOLYSHEEP_BASE_URL="https://api.holysheep.ai/v1"
DATA_DIR="/opt/reports/data"
OUTPUT_DIR="/opt/reports/output"
MODEL="gpt-4.1"
LOG_FILE="/var/log/holy sheep_batch.log"
============================================================
LOGGING
============================================================
log() {
echo "[$(date '+%Y-%m-%d %H:%M:%S')] $*" | tee -a "$LOG_FILE"
}
log_error() {
echo "[$(date '+%Y-%m-%d %H:%M:%S')] ERROR: $*" | tee -a "$LOG_FILE" >&2
}
============================================================
HELPER FUNCTIONS
============================================================
encode_base64() {
base64 -w 0 "$1"
}
count_tokens() {
# Rough estimate: 4 characters per token
wc -c < "$1" | awk '{print int($1 / 4)}'
}
estimate_cost() {
local tokens=$1
local rate=8 # $8 per MTok for GPT-4.1
echo "scale=4; ($tokens / 1000000) * $rate" | bc
}
============================================================
PROCESS SINGLE FILE
============================================================
process_file() {
local input_file="$1"
local file_name=$(basename "$input_file")
local file_ext="${file_name##*.}"
local output_file="${OUTPUT_DIR}/${file_name%.${file_ext}}_analysis.json"
log "Processing: $file_name"
# Encode file to base64
local base64_content=$(encode_base64 "$input_file")
# Determine file type
local file_type="csv"
if [[ "$file_ext" == "xlsx" || "$file_ext" == "xls" ]]; then
file_type="excel"
fi
# Estimate tokens and cost
local token_estimate=$(count_tokens "$input_file")
local cost_estimate=$(estimate_cost "$token_estimate")
log " Estimated tokens: ~$token_estimate | Est. cost: \$$cost_estimate"
# Make API request
local response=$(curl -s -X POST "${HOLYSHEEP_BASE_URL}/chat/completions" \
-H "Authorization: Bearer ${HOLYSHEEP_API_KEY}" \
-H "Content-Type: application/json" \
-d "{
\"model\": \"${MODEL}\",
\"messages\": [
{
\"role\": \"system\",
\"content\": \"You are an expert data analyst. Analyze the provided file and return structured JSON.\"
},
{
\"role\": \"user\",
\"content\": [
{
\"type\": \"text\",
\"text\": \"Analyze this ${file_type} file. Provide summary statistics, key insights, and any anomalies. Return as JSON.\"
},
{
\"type\": \"file\",
\"file_data\": {
\"filename\": \"${file_name}\",
\"file_type\": \"${file_type}\",
\"content_base64\": \"${base64_content}\"
}
}
]
}
],
\"response_format\": { \"type\": \"json_object\" },
\"temperature\": 0.1
}")
# Check for errors
if echo "$response" | grep -q '"error"'; then
log_error "API error for $file_name: $(echo "$response" | jq -r '.error.message')"
return 1
fi
# Extract and save content
echo "$response" | jq -r '.choices[0].message.content' > "$output_file"
# Save metadata
local tokens_used=$(echo "$response" | jq -r '.usage.total_tokens')
local cost=$(estimate_cost "$tokens_used")
jq --arg file "$file_name" \
--arg tokens "$tokens_used" \
--arg cost "$cost" \
--argjson timestamp "$(date +%s)" \
'{$file, $tokens, $cost, $timestamp, analysis: .}' \
<<< "$(cat "$output_file")" > "${output_file}.meta.json"
log " ✓ Completed: $output_file (tokens: $tokens_used, cost: \$$cost)"
}
============================================================
MAIN EXECUTION
============================================================
main() {
log "=========================================="
log "HolySheep Batch Report Generator Started"
log "=========================================="
# Validate configuration
if [[ ! -d "$DATA_DIR" ]]; then
log_error "Data directory not found: $DATA_DIR"
exit 1
fi
# Create output directory
mkdir -p "$OUTPUT_DIR"
# Count files
local xlsx_count=$(find "$DATA_DIR" -maxdepth 1 -type f \( -name "*.xlsx" -o -name "*.xls" \) | wc -l)
local csv_count=$(find "$DATA_DIR" -maxdepth 1 -type f -name "*.csv" | wc -l)
local total_files=$((xlsx_count + csv_count))
log "Found $total_files files to process ($xlsx_count Excel, $csv_count CSV)"
if [[ $total_files -eq 0 ]]; then
log "No files to process. Exiting."
exit 0
fi
# Process files
local success_count=0
local error_count=0
local total_tokens=0
local total_cost=0
for file in "$DATA_DIR"/*.xlsx "$DATA_DIR"/*.xls "$DATA_DIR"/*.csv; do
[[ -e "$file" ]] || continue
if process_file "$file"; then
((success_count++))
# Extract tokens from metadata
if [[ -f "${file%.${file##*.}}_analysis.json.meta.json" ]]; then
tokens=$(jq -r '.tokens' "${file%.${file##*.}}_analysis.json.meta.json" 2>/dev/null || echo 0)
total_tokens=$((total_tokens + tokens))
fi
else
((error_count++))
fi
done
total_cost=$(estimate_cost "$total_tokens")
# Generate summary report
local summary_file="${OUTPUT_DIR}/batch_summary_$(date +%Y%m%d_%H%M%S).json"
cat > "$summary_file" << EOF
{
"batch_id": "$(uuidgen 2>/dev/null || date +%s)",
"timestamp": "$(date -Iseconds)",
"source_directory": "$DATA_DIR",
"output_directory": "$OUTPUT_DIR",
"statistics": {
"total_files": $total_files,
"successful": $success_count,
"failed": $error_count,
"excel_files": $xlsx_count,
"csv_files": $csv_count
},
"usage": {
"total_tokens": $total_tokens,
"estimated_cost_usd": $total_cost
},
"model": "$MODEL"
}
EOF
log "=========================================="
log "Batch Complete!"
log " Total files: $total_files"
log " Successful: $success_count"
log " Failed: $error_count"
log " Total tokens: $total_tokens"
log " Total cost: \$$total_cost"
log " Summary: $summary_file"
log "=========================================="
# Send notification (configure webhook URL as needed)
if [[ -n "${WEBHOOK_URL:-}" ]]; then
curl -s -X POST "$WEBHOOK_URL" \
-H "Content-Type: application/json" \
-d "{\"text\": \"HolySheep batch complete: $success_count/$total_files files processed, \$$total_cost\"}" \
|| log_error "Failed to send webhook notification"
fi
}
Run main function
main "$@"
Advanced: Integrating with Existing Data Pipelines
If you are already using Apache Airflow, Prefect, or Dagster, here is how to integrate HolySheep batch processing into your existing workflows.
# Apache Airflow DAG Example: Daily Report Generation with HolySheep AI
from airflow import DAG
from airflow.operators.python import PythonOperator
from airflow.operators.bash import BashOperator
from datetime import datetime, timedelta
import json
import requests
HolySheep Configuration
HOLYSHEEP_BASE_URL = "https://api.holysheep.ai/v1"
HOLYSHEEP_API_KEY = "YOUR_HOLYSHEEP_API_KEY"
default_args = {
'owner': 'data-engineering',
'depends_on_past': False,
'start_date': datetime(2026, 1, 1),
'email_on_failure': True,
'email_on_retry': False,
'retries': 3,
'retry_delay': timedelta(minutes=5),
}
dag = DAG(
'holy_sheep_batch_reports',
default_args=default_args,
description='Daily batch report generation using HolySheep AI',
schedule_interval='0 3 * * *', # Run at 3 AM daily
catchup=False,
max_active_runs=1,
)
def extract_files(**context):
"""Extract files from S3/database and stage for processing."""
import boto3
from pathlib import Path
s3_client = boto3.client('s3')
bucket = 'your-data-bucket'
prefix = f"reports/{context['ds']}/"
# List files to process
response = s3_client.list_objects_v2(Bucket=bucket, Prefix=prefix)
files = [obj['Key'] for obj in response.get('Contents', [])]
# Download to local staging
staging_dir = Path('/tmp/holy_sheep_batch')
staging_dir.mkdir(exist_ok=True)
for file_key in files:
if file_key.endswith(('.xlsx', '.xls', '.csv')):
local_path = staging_dir / file_key.split('/')[-1]
s3_client.download_file(bucket, file_key, str(local_path))
context['ti'].xcom_push(key='files', value=list(staging_dir.glob('*.*')))
context['ti'].xcom_push(key='file_count', value=len(files))
return len(files)
def process_batch_with_holy_sheep(**context):
"""Process files through HolySheep AI API."""
import base64
from pathlib import Path
files = context['ti'].xcom_pull(key='files', task_ids='extract_files')
headers = {
"Authorization": f"Bearer {HOLYSHEEP_API_KEY}",
"Content-Type": "application/json"
}
results = []
total_tokens = 0
for file_path in files:
file_path = Path(file_path)
with open(file_path, 'rb') as f:
base64_content = base64.b64encode(f.read()).decode('utf-8')
file_type = 'excel' if file_path.suffix in ['.xlsx', '.xls'] else 'csv'
payload = {
"model": "gpt-4.1",
"messages": [
{
"role": "system",
"content": "You are an expert data analyst. Analyze the provided file and return structured JSON."
},
{
"role": "user",
"content": [
{
"type": "text",
"text": "Perform comprehensive analysis. Return JSON with: summary, statistics, insights, anomalies."
},
{
"type": "file",
"file_data": {
"filename": file_path.name,
"file_type":