A FastAPI service that analyzes call center transcripts using the Anthropic Claude API. Submit a transcript and receive a structured QA score, call summary, and sentiment classification.
- QA Scoring — 1–10 score based on call quality
- Summarization — 2–3 sentence summary of the call
- Sentiment Analysis —
positive,neutral, ornegative - Structured JSON responses validated with Pydantic
- Retry logic with exponential backoff for transient API failures
- JSON structured logging with per-request IDs
app/
├── main.py # FastAPI entry point
├── api/
│ ├── routes.py # POST /analyze-transcript endpoint
│ └── middleware.py # Request logging middleware
├── services/
│ └── claude_service.py # Claude API interaction
├── models/
│ └── schemas.py # Request/response Pydantic models
└── core/
├── config.py # Settings (env-based)
├── logging.py # JSON logger
└── resilience.py # Retry decorator
- Python 3.12+
- An Anthropic API key
1. Clone and create a virtual environment
git clone <repo-url>
cd call-transcript-analysis
python -m venv .venv
source .venv/bin/activate # Windows: .venv\Scripts\activate2. Install dependencies
pip install -r requirements.txt3. Configure environment
cp .env.example .envEdit .env:
ANTHROPIC_API_KEY=your-api-key-here
CLAUDE_MODEL=claude-sonnet-4-6
CLAUDE_TIMEOUT_SECONDS=30
CLAUDE_MAX_RETRIES=3uvicorn app.main:app --reloadThe API will be available at http://localhost:8000.
Interactive docs: http://localhost:8000/docs
Analyzes a call center transcript.
Request
{
"transcript": "Agent: Thank you for calling. How can I help?\nCustomer: ..."
}| Field | Type | Constraints |
|---|---|---|
transcript |
string | 1–50,000 characters, non-blank |
Response 200 OK
{
"qa_score": 8,
"summary": "The agent resolved the customer's billing issue efficiently and with a friendly tone.",
"sentiment": "positive"
}| Field | Type | Values |
|---|---|---|
qa_score |
integer | 1–10 |
summary |
string | 1–2 sentence call summary |
sentiment |
string | "positive", "neutral", "negative" |
Error responses
| Status | Reason |
|---|---|
422 |
Invalid or missing transcript input |
503 |
Claude API unavailable or misconfigured |
Transient failures (rate limits, timeouts, server errors) are retried automatically with exponential backoff. The number of retries is controlled by CLAUDE_MAX_RETRIES (default: 3).
| Layer | Library |
|---|---|
| Web framework | FastAPI + Uvicorn |
| Validation | Pydantic v2 |
| AI | Anthropic SDK (claude-sonnet-4-6) |
| HTTP client | HTTPX |
| Retry | Tenacity |
| Config | pydantic-settings + dotenv |