Introduction
The PDF AI API allows you to create AI-powered chat sessions with your PDF documents. Upload a PDF, create a chat session, and interact with your document content through natural language conversations powered by GPT-4 and semantic search.Base URL
All API endpoints are relative to your deployment URL:Authentication
The API uses Clerk authentication for user management. Most endpoints require a valid authentication token:- Create Chat: Requires authentication (Clerk userId)
- Chat: No authentication required (uses chatId for authorization)
- Get Messages: No authentication required (uses chatId for authorization)
Core Concepts
Chats
A chat represents a conversation session with a specific PDF document. Each chat is associated with:- A PDF file stored in S3
- Vector embeddings stored in Pinecone for semantic search
- A collection of messages exchanged between the user and AI
Messages
Messages are the individual exchanges within a chat. Each message has:- role: Either
user(human input) orsystem(AI response) - content: The text content of the message
- chatId: Reference to the parent chat session
Context Retrieval
The API uses RAG (Retrieval-Augmented Generation) to provide relevant responses:- User query is embedded using OpenAI embeddings
- Similar content is retrieved from Pinecone vector store
- Retrieved context is injected into the GPT-4 prompt
- AI generates a response based on the PDF content
API Endpoints
Create Chat
Create a new chat session from an uploaded PDF
Chat
Send messages and receive AI responses (streaming)
Get Messages
Retrieve message history for a chat session
Response Format
All non-streaming API endpoints return JSON responses.Success Response
Error Response
Error Codes
| Status Code | Description |
|---|---|
| 200 | Success |
| 401 | Authentication error - invalid or missing credentials |
| 404 | Resource not found (e.g., chat doesn’t exist) |
| 500 | Internal server error |
Rate Limits
Rate limits depend on your deployment configuration and OpenAI API quota. Monitor your usage to avoid hitting limits.
Edge Runtime
The Chat and Get Messages endpoints run on Vercel’s Edge Runtime for optimal performance and low latency worldwide.Getting Started
- Upload a PDF to S3 and obtain a
file_key - Create a chat using the
/api/create-chatendpoint - Send messages using the
/api/chatendpoint - Retrieve history using the
/api/get-messagesendpoint