Automatically tests and maps file-upload API endpoints using AI (Google Gemini Vision).
This tool scans a Postman collection, detects which APIs require file uploads, and tests them intelligently with real documents.
It uses Google Gemini AI for document classification (OCR + understanding) and error interpretation to automatically learn which document types each API accepts.
β
Gemini-powered document classification β Reads and understands PDFs or images using OCR.
β
Auto-detect upload APIs β Finds endpoints that expect file uploads in your Postman collection.
β
Smart error understanding β Uses LLM reasoning to extract what document type or format the API wants.
β
Auto-retry with correct document β Retests failed APIs with the right file type automatically.
β
Comprehensive JSON report β Summarizes which APIs succeeded, failed, or were skipped.
β
Caching β Saves document classifications and Gemini uploads to save time and cost.
βββββββββββββββββββββββββββββββββ
β Local Documents Folder β
β (PDFs, images, etc.) β
ββββββββββββββββ¬βββββββββββββββββ
β
ββββββββββββββββββΌβββββββββββββββββ
β Gemini Vision (via SDK) β
β β OCR + classify each doc β
ββββββββββββββββββ¬βββββββββββββββββ
β
βββββββββββββββΌβββββββββββββββ
β Postman Collection β
β β find upload endpoints β
βββββββββββββββ¬βββββββββββββββ
β
ββββββββββββββββββββββββΌββββββββββββββββββββββββββββ
β For each API: β
β 1οΈβ£ Pick random doc and test β
β 2οΈβ£ If error, interpret it with Gemini β
β 3οΈβ£ Retry with correct doc type β
ββββββββββββββββββββββββ¬ββββββββββββββββββββββββββββ
β
ββββββββββββΌββββββββββββ
β Generate Report.json β
β β success, failure, β
β and doc mappings β
ββββββββββββββββββββββββ
π¦ api-document-mapper/
βββ main.py # Main script (CLI entry)
βββ prompts/
β βββ classify_document.md # System prompt for doc classification
β βββ normalize_error.md # System prompt for error interpretation
βββ .env # Contains GOOGLE_API_KEY
βββ sample_docs/ # Folder with test documents
βββ postman_collection.json # Postman collection file
βββ outputs/
βββ document_classifications.json # Cached Gemini classification results
βββ report.json # Final report of API tests
git clone https://github.com/yourusername/api-document-mapper.git
cd api-document-mapperpython -m venv venv
source venv/bin/activate # (Mac/Linux)
venv\Scripts\activate # (Windows)pip install -r requirements.txtCreate a .env file in the project root and add:
GOOGLE_API_KEY=your_google_gemini_api_key_herePlace your test documents (PDFs, images, etc.) in a folder like ./sample_docs/.
Export your collection and environment from Postman as JSON files.
python main.py \
--postman ./postman_collection.json \
--env ./postman_env.json \
--docs ./sample_docs \
--out ./outputs \
--random-file-per-apiAfter running, a structured report appears in outputs/report.json.
[
{
"api_name": "Upload KYC Document",
"path": "https://api.example.com/upload",
"accepted_documents": [
{ "fileName": "pan_card.pdf", "docType": "PAN card" }
],
"rejected_documents": [
{ "nameOfFile": "passport.jpg", "docType": "passport", "errorMessage": "Invalid document type" }
],
"skipped_documents": [
{ "fileName": "blurry_scan.png", "reason": "classification failed" }
]
}
]This project uses Googleβs official Python SDK for the Gemini models.
import google.generativeai as genai
genai.configure(api_key="YOUR_GOOGLE_API_KEY")
model = genai.GenerativeModel("gemini-2.5-pro")
# Upload a file
file_ref = genai.upload_file("pan_card.pdf")
# Ask Gemini to classify it
response = model.generate_content([file_ref, "Classify this document"])
print(response.text)| Tier | Description | Function |
|---|---|---|
| 1οΈβ£ | Use structured API errors if they already include required info | Direct JSON check |
| 2οΈβ£ | Quick pattern match for common words (pdf, aadhaar, etc.) |
cheap_error_to_struct() |
| 3οΈβ£ | Ask Gemini to interpret vague or unstructured errors | normalize_error_with_gemini() |
You are a document classification model.
Analyze the attached file (image or PDF) and identify the document type.
Return only valid JSON:
{
"document_type": "<type>",
"confidence": <float between 0 and 1>
}You are an API response analyzer.
Given an HTTP status, headers, and body, identify:
- required document type (if any)
- required file extension type (if any)
Return JSON in the shape:
{
"required_extension_type": "<ext or null>",
"required_document_type": "<type or null>",
"description": "<plain explanation>"
}| Tool | Purpose |
|---|---|
| Python 3.9+ | Main programming language |
| Pydantic | Data validation and modeling |
| Requests | Making HTTP calls to test APIs |
| Google Gemini SDK | AI classification and reasoning |
| dotenv | Loading environment variables |
| Postman JSON | Source of API endpoints |
| API Name | Accepted Docs | Rejected Docs | Notes |
|---|---|---|---|
| Upload PAN | pan_card.pdf |
passport.jpg |
Retry succeeded |
| Upload Address Proof | utility_bill.pdf |
β | Success on first try |
- β‘ Parallelize API testing for speed
- π Add OAuth or Bearer token handling
- π Build a simple web dashboard for report visualization
- π§© Improve document-type ontology (fuzzy matching, synonyms)
Pull requests and suggestions are welcome! To contribute:
- Fork the repo
- Create a new branch (
feature/your-feature) - Commit and push your changes
- Submit a Pull Request π
π‘ βAI shouldnβt just test your APIs β it should understand them.β