AskYourPDF API Documentation
Introducing the AskYourPDF API
AskYourPDF is a cutting-edge solution revolutionizing document interactions. Our API empowers developers with the ability to programmatically extract valuable information from PDF files and leverage it to create custom chatbots. By providing seamless access to the content within PDF documents, developers can build powerful applications that enable users to navigate, search, and engage with data effortlessly. This comprehensive guide will walk you through the API's features, pricing, authentication methods, and usage guidelines, opening up endless possibilities to enhance productivity and knowledge retrieval for your applications. Harness the potential of AskYourPDF API and embark on an innovative journey of intelligent document analysis and interactive experiences.
Uploading A Document
To upload a document, choose between generating a document ID on our website or using the API endpoint. We support various document formats, including '.pdf', '.txt', '.ppt', '.pptx', '.csv', '.epub', and '.rtf'. Additionally, you can upload PDFs using links. Moreover, the API enables interaction with any blog post or website by providing the link to the post.
Authentication
Authentication is required for all our API endpoints. To access them, you must generate API keys on your AskYourPDF account. These API keys need to be set in your request header as "x-api-key." It is essential to treat your API key as a secret and ensure its protection.
headers: {
"x-api-key": "ask_xxxxx"
}
1. Adding Document via URL
Download a PDF file from a URL and save it to the database.
Args: user: The user who is uploading the file. url: The URL of the PDF file to download.
Returns: dict: The document ID of the downloaded file.
Successful Response
Validation Error
Query Parameters:
url(required): The link to the document. It could be a link to a PDF or a post on a website
Response:
201Successful Responsedoc_id(string): The document ID of the uploaded document.
Examples:
2. Adding Document via File Upload
Request body:
The request body should be sent as a form of data with the name file (see example).
file(required): The raw bytes of the file to be uploaded.
Response:
201Successful Responsedoc_id(string): The document ID of the uploaded document.
Examples:
3. Chat Endpoint
Endpoint for initiating a chat with a document. This endpoint requires API Key Header authentication.
Path Parameters:
doc_id (string, required): The ID of the document for the conversation.
Query Parameters:
stream(boolean, optional): Flag for streaming. Default isfalsemodel_name (string, optional) : The model the user chooses to use, model choices includes CLAUDE1, CLAUDE2, GPT3, GPT4, GPT4O_MINI. Default model is GPT4O_MINI
cite_source (boolean, optional) : Flag for cite_sources. Default if false
temeperature (float, optional) : Flag for temperature. Default is 0.7
language (string, optional) : The language the user chooses to chat with, language choices include ENGLISH, ARABIC, CHINESE, JAPANESE, FRENCH , GERMAN, SPANISH, KOREAN, PORTUGESE. Default language is ENGLISH.
length (string, optional) : This option allows you to choose the desired length of the response. Choices includes LONG and SHORT. Default value is SHORT
Request body:
sender(required): The sender of the chat message. The sender should beUsermessage(required): The chat message content.
The request body to ask a single question.
To ask a follow-up question and provide the model with context you can send your previous questions and responses in the following format.
Response:
The response when the query parameter stream = False
200Successful Responsequestion: The question posed by the user, with sender, message, and type.sendermessagetype
answer: The answer provided by the AI, with sender, message, and type.sendermessagetype
created(string): The time the chat was created.
By setting the query parameter stream = True, you can receive the response as a stream of token. An example of the response can be seen below.
Example when stream = False:
Example when stream = True:
4. Chat with multiple documents
This endpoint allows a user to chat with more than one docuemt.
Query paramters
stream(boolean, optional): Flag for streaming. Default isfalsemodel_name (string, optional) : The model the user chooses to use, model choices includes CLAUDE1, CLAUDE2, GPT3, GPT4, GPT4O_MINI. Default model is GPT4O_MINI
cite_source (boolean, optional) : Flag for cite_sources. Default if false
temperature (float, optional) : Flag for temperature. Default is 0.7
language (string, optional) : The language the user chooses to chat with, language choices include ENGLISH, ARABIC, CHINESE, JAPANESE, FRENCH , GERMAN, SPANISH, KOREAN, PORTUGESE. Default language is ENGLISH.
length (string, optional) : This option allows you to choose the desired length of the response. Choices includes LONG and SHORT. Default value is SHORT
Body
Response:
200 : Successful Response
question : A dict of information directed to the model
sender : The sender of the question,
message : The question asked
type : Has a value of "question"
answer : A dict of response information from the model
sender : The sender of the response
message : The exact answer a user requested
type : Has a value of "response"
Examples
5. Documents Retrieval Endpoint
This endpoint allows users to retrieve a paginated list of their uploaded documents.
Query Parameters:
page(integer, optional): The page to return. Defaults to1.page_size (integer, optional): The number of documents to return per page. Defaults to 10.
Response:
200Successful Responsetotal_pages(Integer): The total number of pages available for queryingdocuments(Array): A list of document details belonging to the user.namedoc_idsummarylanguagepagesshareabledate_time
Examples:
6. Single Document Retrieval Endpoint
This endpoint allows users to retrieve a single document.
Path Parameters:
doc_id (string, required): The ID of the document for the conversation.
Response:
200Successful Responsenamedoc_idsummarylanguagepagesshareabledate_time
Examples:
7. Delete Document Endpoint
Allows users to delete a single document
Path Parameters:
doc_id (string, required): The ID of the document to be deleted.
Response:
200Successful Response
Examples:
KnowledgeBase Endpoints
Knowledgebase endpoints are used when a user wants to chat or interact with multiple documents
8. Get Knowledge Bases
This endpoint enables an authenticated user to retrieve paginated knowledgebases Returns: PaginatedKnowledgeBase: The response containing the updated knowledge base.
Query parameters
page (integer, optional)
page_size (integer, optional)
order (string optional)
Response
200 Successful Response
total_pages (Integer): The total number of pages available for querying
knowledge_bases : An array of knowledges bases being queried
422 : Validation Error
Examples
9. Create Knowledge Base
This endpoint enables a user to create a knowlege base from the list of document IDs
Returns: KnowledgeBaseResponse: The response containing the knowledge base ID.
Body
name * (string, required) : The name of the knowledgebase
document_ids * (array, required) : The documents Ids to be included in the knowledgebase
Response
201 : Successful Response
KnowlegeBaseResponse : A dictionary of knowledge_base_id created
422: Validation Error
Examples
curl -X POST 'https://api.askyourpdf.com/v1/api/knowledge' -H 'x-api-key: YOUR_API_KEY' -H 'Content-Type: application/json' -d '{ "name": "string", "document_ids": [ "string" ] }'
10. Get KnowledgeBase
This endpoint enables a user to retrieve a single knowledge base
Args: knowledge_base_id: The ID of the knowledge base to retrieve
Returns: KnowledgeDetailedResponse: The response containing the updated knowledge base.
Path parameter
knowledge_base_id * (string, required)
Response
200 : Succesful Response
422 : Validator Error
Examples
curl -X GET 'https://api.askyourpdf.com/v1/api/knowledge/YOUR_KNOWLEDGE_BASE_ID' -H 'x-api-key: YOUR_API_KEY'
11. Update Knowledge Base
This endpoint enables a user to update a knowledge base
Args: knowledge_base_id: The ID of the knowledge base to update.
Returns: KnowledgeDetailedResponse: The response containing the updated knowledge base.
Path parameter
knowledge_base_id* (string, required)
Body
name (string) : A new name for your knowledge base
document_ids: (string) An array of documents IDs you wish to update your knowledgebase with
Response
200 : Successful Response
422 : Validator Error
Examples
12. Delete Knowledge Base
This endpoint enables a user to delete a knowledge base
Args: knowledge_base_id: The ID of the knowledge base to delete
Returns: dict: The response containing a success message
Path parameter
knowledge_base_id* (string, required)
Response
200 : Successful Response
Examples
curl -X DELETE 'https://api.askyourpdf.com/v1/api/knowledge/YOUR_KNOWLEDGE_BASE_ID' -H 'x-api-key: YOUR_API_KEY'
13. Search Knowledge Base
This endpoint retrieves a list of knowledgebases based on a user's query
Args: query: The search query is used to filter knowledgebases by name
Returns: KnowledgeBase: A list of knowledges matching the query
Query parameter
query* (string, required)
Response
200 : Successful Response
422 : Validator Error
Examples
curl -X GET 'https://api.askyourpdf.com/v1/api/search/knowledge?query=YOUR_QUERY' -H 'x-api-key: YOUR_API_KEY'
Last updated