# 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** &#x20;

To upload a document, choose between [generating a document](https://askyourpdf.com/upload) 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**&#x20;

Authentication is required for all our API endpoints. To access them, you must [generate API keys](https://askyourpdf.com/developers/apiKeys) 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.

```json
headers: {
    "x-api-key": "ask_xxxxx"
  }

```

##

## **1.  Adding Document via URL**

## Download Pdf

> Download a PDF file from a URL and save it to the database.\
> \
> Args:\
> &#x20;   user: The user who is uploading the file.\
> &#x20;   url: The URL of the PDF file to download.\
> \
> Returns:\
> &#x20;   dict: The document ID of the downloaded file.

```json
{"openapi":"3.1.0","info":{"title":"FastAPI","version":"0.1.0"},"security":[{"APIKeyHeader":[]}],"components":{"securitySchemes":{"APIKeyHeader":{"type":"apiKey","in":"header","name":"X-API-Key"}},"schemas":{"DocumentUploadResponse":{"properties":{"docId":{"type":"string","title":"Docid"}},"type":"object","required":["docId"],"title":"DocumentUploadResponse","description":"Response for document upload"},"HTTPValidationError":{"properties":{"detail":{"items":{"$ref":"#/components/schemas/ValidationError"},"type":"array","title":"Detail"}},"type":"object","title":"HTTPValidationError"},"ValidationError":{"properties":{"loc":{"items":{"anyOf":[{"type":"string"},{"type":"integer"}]},"type":"array","title":"Location"},"msg":{"type":"string","title":"Message"},"type":{"type":"string","title":"Error Type"}},"type":"object","required":["loc","msg","type"],"title":"ValidationError"}}},"paths":{"/v1/api/download_pdf":{"get":{"tags":["document","document"],"summary":"Download Pdf","description":"Download a PDF file from a URL and save it to the database.\n\nArgs:\n    user: The user who is uploading the file.\n    url: The URL of the PDF file to download.\n\nReturns:\n    dict: The document ID of the downloaded file.","operationId":"download_pdf_v1_api_download_pdf_get","parameters":[{"name":"url","in":"query","required":true,"schema":{"type":"string","title":"Url"}}],"responses":{"201":{"description":"Successful Response","content":{"application/json":{"schema":{"$ref":"#/components/schemas/DocumentUploadResponse"}}}},"422":{"description":"Validation Error","content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPValidationError"}}}}}}}}}
```

### **Query Parameters:**

* `url` (required): The link to the document. It could be a link to a PDF or a post on a website

### **Response:**

* `201` Successful Response
  * `doc_id` (`string`): The document ID of the uploaded document.

```json
{ "doc_id": "6e60e87c-6154-4dff-8e62-ff10d8ed16dd" }
```

### **Examples:**

{% code title="cURL" %}

```markup
curl -X GET 
'https://api.askyourpdf.com/v1/api/download_pdf?url=https://www.example.com/document.pdf' 
-H 'x-api-key: YOUR_API_KEY'

```

{% endcode %}

{% code title="Python" %}

```python
import requests

headers = {
    'x-api-key': 'YOUR_API_KEY'
}

response = requests.get('https://api.askyourpdf.com/v1/api/download_pdf', 
headers=headers, 
params={'url': 'https://www.example.com/document.pdf'})

if response.status_code == 201:
    print(response.json())
else:
    print('Error:', response.status_code)
```

{% endcode %}

{% code title="Javascript" %}

```javascript
const axios = require('axios');

const headers = {
    'x-api-key': 'YOUR_API_KEY'
};

axios.get('https://api.askyourpdf.com/v1/api/download_pdf', {
  headers: headers,
  params: {
    url: 'https://www.example.com/document.pdf'
  }
})
.then((response) => {
  if (response.status === 201) {
    console.log(response.data);
  } else {
    console.log('Error:', response.status);
  }
})
.catch((error) => {
  console.error(error);
});
```

{% endcode %}

##

## **2. Adding Document via File Upload.**

## Upload Pdf

> Upload a PDF file and save it to the database.\
> \
> Args:\
> &#x20;   user: The user who is uploading the file.\
> &#x20;   file: The PDF file to upload.\
> \
> Returns:\
> &#x20;   dict: The document ID of the uploaded file.

```json
{"openapi":"3.1.0","info":{"title":"FastAPI","version":"0.1.0"},"security":[{"APIKeyHeader":[]}],"components":{"securitySchemes":{"APIKeyHeader":{"type":"apiKey","in":"header","name":"X-API-Key"}},"schemas":{"Body_upload_pdf_v1_api_upload_post":{"properties":{"file":{"type":"string","format":"binary","title":"File"}},"type":"object","required":["file"],"title":"Body_upload_pdf_v1_api_upload_post"},"DocumentUploadResponse":{"properties":{"docId":{"type":"string","title":"Docid"}},"type":"object","required":["docId"],"title":"DocumentUploadResponse","description":"Response for document upload"},"HTTPValidationError":{"properties":{"detail":{"items":{"$ref":"#/components/schemas/ValidationError"},"type":"array","title":"Detail"}},"type":"object","title":"HTTPValidationError"},"ValidationError":{"properties":{"loc":{"items":{"anyOf":[{"type":"string"},{"type":"integer"}]},"type":"array","title":"Location"},"msg":{"type":"string","title":"Message"},"type":{"type":"string","title":"Error Type"}},"type":"object","required":["loc","msg","type"],"title":"ValidationError"}}},"paths":{"/v1/api/upload":{"post":{"tags":["document","document"],"summary":"Upload Pdf","description":"Upload a PDF file and save it to the database.\n\nArgs:\n    user: The user who is uploading the file.\n    file: The PDF file to upload.\n\nReturns:\n    dict: The document ID of the uploaded file.","operationId":"upload_pdf_v1_api_upload_post","requestBody":{"content":{"multipart/form-data":{"schema":{"$ref":"#/components/schemas/Body_upload_pdf_v1_api_upload_post"}}},"required":true},"responses":{"201":{"description":"Successful Response","content":{"application/json":{"schema":{"$ref":"#/components/schemas/DocumentUploadResponse"}}}},"422":{"description":"Validation Error","content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPValidationError"}}}}}}}}}
```

### **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:**

* `201` Successful Response
  * `doc_id` (`string`): The document ID of the uploaded document.

```json
{ "doc_id": "6e60e87c-6154-4dff-8e62-ff10d8ed16dd" }
```

### **Examples:**

{% code title="cURL" %}

```markup
curl -X POST 
-H 'x-api-key: YOUR_API_KEY' 
-F "file=@/path/to/yourfile.pdf" https://api.askyourpdf.com/v1/api/upload


```

{% endcode %}

{% code title="Python" %}

```python
import requests

headers = {
    'x-api-key': 'YOUR_API_KEY'
}

file_data = open('/path/to/yourfile.pdf', 'rb')

response = requests.post('https://api.askyourpdf.com/v1/api/upload', headers=headers,
 files={'file': file_data})

if response.status_code == 201:
    print(response.json())
else:
    print('Error:', response.status_code)

```

{% endcode %}

{% code title="Javascript" %}

```javascript
const axios = require('axios');
const FormData = require('form-data');
const fs = require('fs');

const headers = {
    'x-api-key': 'YOUR_API_KEY'
};

let form = new FormData();
form.append('file', fs.createReadStream('/path/to/yourfile.pdf'));

axios.post('https://api.askyourpdf.com/v1/api/upload', form, {
  headers: {
    ...headers,
    ...form.getHeaders()
  }
})
.then((response) => {
  if (response.status === 201) {
    console.log(response.data);
  } else {
    console.log('Error:', response.status);
  }
})
.catch((error) => {
  console.error(error);
});

```

{% endcode %}

##

## **3. Chat Endpoint**

Endpoint for initiating a chat with a document. This endpoint requires API Key Header authentication.

## Chat With Doc Endpoint

> Chat with a single document.\
> \
> Args:\
> &#x20;   doc\_id: The document id.\
> &#x20;   model\_name: The model name.\
> &#x20;   messages: The list of messages.\
> &#x20;   cite\_source: Whether to cite the source or not.\
> &#x20;   temperature: The model temperature max value is 1.5 and min value is 0.1.\
> &#x20;   language: The language to respond in.\
> &#x20;   length: The length of the response\
> &#x20;   stream: Whether to stream the response or not.\
> &#x20;   agent\_mode: Whether to use agent mode or not.\
> &#x20;   user: The current user.\
> \
> Returns:\
> &#x20;   ChatSerializer: The chat response.

```json
{"openapi":"3.1.0","info":{"title":"FastAPI","version":"0.1.0"},"security":[{"APIKeyHeader":[]}],"components":{"securitySchemes":{"APIKeyHeader":{"type":"apiKey","in":"header","name":"X-API-Key"}},"schemas":{"AIModelType":{"type":"string","enum":["CLAUDE1","CLAUDE2","GPT3","GPT4","GPT4O_MINI","GEMINI_FLASH","GEMINI_PRO","GPT5_MINI","GPT5_2","GPT5_NANO","GPT5"],"title":"AIModelType"},"LANGUAGE":{"type":"string","enum":["DEFAULT","ENGLISH","FRENCH","GERMAN","SPANISH","CHINESE","JAPANESE","KOREAN","PORTUGUESE","ARABIC","ITALIAN","TURKISH","HEBREW","DUTCH"],"title":"LANGUAGE"},"ChatResponseLengthChoice":{"type":"string","enum":["SHORT","LONG"],"title":"ChatResponseLengthChoice"},"ChatRequest":{"properties":{"sender":{"type":"string","title":"Sender"},"message":{"type":"string","title":"Message"}},"type":"object","required":["sender","message"],"title":"ChatRequest","description":"ChatRequest response schema."},"ChatSerializer":{"properties":{"question":{"$ref":"#/components/schemas/ChatResponse"},"answer":{"$ref":"#/components/schemas/ChatResponse"},"created":{"type":"string","format":"date-time","title":"Created"}},"type":"object","required":["question","answer"],"title":"ChatSerializer"},"ChatResponse":{"properties":{"sender":{"type":"string","title":"Sender"},"message":{"type":"string","title":"Message"},"type":{"type":"string","title":"Type"}},"type":"object","required":["sender","message","type"],"title":"ChatResponse","description":"ChatResponse response schema."},"HTTPValidationError":{"properties":{"detail":{"items":{"$ref":"#/components/schemas/ValidationError"},"type":"array","title":"Detail"}},"type":"object","title":"HTTPValidationError"},"ValidationError":{"properties":{"loc":{"items":{"anyOf":[{"type":"string"},{"type":"integer"}]},"type":"array","title":"Location"},"msg":{"type":"string","title":"Message"},"type":{"type":"string","title":"Error Type"}},"type":"object","required":["loc","msg","type"],"title":"ValidationError"}}},"paths":{"/v1/chat/{doc_id}":{"post":{"tags":["chat","chat"],"summary":"Chat With Doc Endpoint","description":"Chat with a single document.\n\nArgs:\n    doc_id: The document id.\n    model_name: The model name.\n    messages: The list of messages.\n    cite_source: Whether to cite the source or not.\n    temperature: The model temperature max value is 1.5 and min value is 0.1.\n    language: The language to respond in.\n    length: The length of the response\n    stream: Whether to stream the response or not.\n    agent_mode: Whether to use agent mode or not.\n    user: The current user.\n\nReturns:\n    ChatSerializer: The chat response.","operationId":"chat_with_doc_endpoint_v1_chat__doc_id__post","parameters":[{"name":"doc_id","in":"path","required":true,"schema":{"type":"string","title":"Doc Id"}},{"name":"model_name","in":"query","required":false,"schema":{"$ref":"#/components/schemas/AIModelType","default":"GPT5_2"}},{"name":"stream","in":"query","required":false,"schema":{"type":"boolean","default":false,"title":"Stream"}},{"name":"cite_source","in":"query","required":false,"schema":{"type":"boolean","default":false,"title":"Cite Source"}},{"name":"temperature","in":"query","required":false,"schema":{"type":"number","default":0.7,"title":"Temperature"}},{"name":"language","in":"query","required":false,"schema":{"$ref":"#/components/schemas/LANGUAGE","default":"DEFAULT"}},{"name":"length","in":"query","required":false,"schema":{"anyOf":[{"$ref":"#/components/schemas/ChatResponseLengthChoice"},{"type":"null"}],"default":"LONG","title":"Length"}},{"name":"agent_mode","in":"query","required":false,"schema":{"type":"boolean","default":true,"title":"Agent Mode"}}],"requestBody":{"required":true,"content":{"application/json":{"schema":{"type":"array","items":{"$ref":"#/components/schemas/ChatRequest"},"title":"Messages"}}}},"responses":{"200":{"description":"Successful Response","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ChatSerializer"}}}},"422":{"description":"Validation Error","content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPValidationError"}}}}}}}}}
```

### **Path Parameters:**

`doc_id` (`string`, required): The ID of the document for the conversation.

### **Query Parameters:**

* `stream` (`boolean`, optional): Flag for streaming. Default is `false`
* model\_name (string, optional) : The model the user chooses to use, model choices includes GPT5\_2, GPT5, GPT5\_MINI, GPT5\_NANO, GEMINI\_FLASH, CLAUDE1, CLAUDE2, GPT4, GPT5, GEMINI\_PRO, GPT4O\_MINI. Default model is GPT5\_2
* agent\_mode (boolean, optional) : Enabled by default. This flag determines whether the system uses our agent to answer your question. When set to `True`, responses may take slightly longer but are generally more accurate and higher quality than those generated in normal mode.
* cite\_source (boolean, optional) :  Flag for cite\_source. Default if false
* temperature (float, optional) : Flag for temperature. Default is 0.7&#x20;
* 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 be `user` or  (`system`If you want to specify a custom system prompt)
* `message` (`required`): The chat message content.

**The request body to ask a single question.**

```json
// Example of a request asking a question along with a system prompt
[
  {
    "sender": "system",
    "message": "Reply to my question in json format"
  },
  {
    "sender": "user",
    "message": "What does this document say?"
  }
]
```

<pre class="language-json"><code class="lang-json">// Example of a request asking a question without a system prompt
[
<strong>  {
</strong>    "sender": "user",
    "message": "What does this document say?"
  }
]
</code></pre>

**To ask a follow-up question and provide the model with context you can send your previous questions and responses in the following format.**

```json
[
    {   
    "sender": "user",
    "message": "What does the document say?"
    },
    {
    "sender": "bot",
    "message": "The document consists of words in different languages expressing gratitude"
     },
   {
    "sender": "user",
    "message": "What is the word expressing gratitude in Spanish?"
    }
]
```

### **Response:**

**The response when the query parameter** `stream = False`

* `200` Successful Response
  * `question`: The question posed by the user, with sender, message, and type.
    * `sender`
    * `message`
    * `type`
  * `answer`: The answer provided by the AI, with sender, message, and type.
    * `sender`
    * `message`
    * `type`
  * `created` (`string`): The time the chat was created.

```json
{
  "question": {
    "sender": "user",
    "message": "What does this document say?",
    "type": "question"
  },
  "answer": {
    "sender": "bot",
    "message": "This document talks about AI",
    "type": "response"
  },
  "created": "2023-07-20T11:14:55.928Z"
}
```

**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.**

```javascript
Chunk: This
Chunk: document
Chunk: talks
Chunk: about
Chunk: AI

```

### **Example when stream = False:**

{% code title="cURL" %}

```markup
curl -X POST 
-H 'Content-Type: application/json' 
-H 'x-api-key: YOUR_API_KEY' 
-d '[{"sender": "User","message": "What does this document say?"}]'
 https://api.askyourpdf.com/v1/chat/{YOUR_DOC_ID}


```

{% endcode %}

{% code title="Python" %}

```python
import requests
import json

headers = {
    'Content-Type': 'application/json',
    'x-api-key': 'YOUR_API_KEY'
}

data = [
    {
        "sender": "User",
        "message": "What does this document say?"
    }
]

response = requests.post('https://api.askyourpdf.com/v1/chat/{YOUR_DOC_ID}', 
headers=headers, data=json.dumps(data))

if response.status_code == 200:
    print(response.json())
else:
    print('Error:', response.status_code)

```

{% endcode %}

{% code title="Javascript" %}

```javascript
const axios = require('axios');

const headers = {
    'Content-Type': 'application/json',
    'x-api-key': 'YOUR_API_KEY'
};

const data = [
    {
        "sender": "User",
        "message": "What does this document say?"
    }
];

axios.post('https://api.askyourpdf.com/v1/chat/{YOUR_DOC_ID}', data, {headers: headers})
.then((response) => {
    if (response.status === 200) {
        console.log(response.data);
    } else {
        console.log('Error:', response.status);
    }
})
.catch((error) => {
    console.error(error);
});
```

{% endcode %}

### **Example when stream = True:**

{% code title="Python" %}

```python
import requests
import json

headers = {
    'Content-Type': 'application/json',
    'x-api-key': 'YOUR_API_KEY'
}

data = [
    {
        "sender": "User",
        "message": "What does this document say?"
    }
]

try:
    response = requests.post(
        'https://api.askyourpdf.com/v1/chat/YOUR_DOC_ID?stream=True',
        headers=headers, data=json.dumps(data))
    response.raise_for_status()

    for chunk in response.iter_content(chunk_size=24):
        chunk_str = chunk.decode('utf-8')
        print("Chunk:", chunk_str)

except requests.exceptions.RequestException as error:
    print("Error:", error)

```

{% endcode %}

{% code title="Javascript" %}

```javascript
const fetch = require('node-fetch');
const Readable = require('stream').Readable;


const headers = {
    'Content-Type': 'application/json',
    'x-api-key': 'YOUR_API_KEY'
}

const data = [
    {
        "sender": "User",
        "message": "What does this document say?"
    }
]

fetch('https://api.askyourpdf.com/v1/chat/YOUR_DOC_ID?stream=True', {
    method: 'POST',
    headers: headers,
    body: JSON.stringify(data)
})
    .then(response => {
        if (!response.ok) {
            throw new Error(`HTTP error! status: ${response.status}`);
        }
        return response.body;
    })
    .then(stream => {
        const reader = Readable.from(stream);
        reader.on('data', chunk => {
            console.log("Chunk:", chunk.toString('utf-8'));
        });
    })
    .catch(error => {
        console.log("Error:", error);
    });
```

{% endcode %}

## 4.  Chat with multiple documents

This endpoint allows a user to chat with more than one document.

## Chat With Multiple Documents

> \[DEPRECATED] Chat with multiple documents using knowledgebase Id.\
> Please use /api/knowledge/{knowledge\_base\_id}/chat instead.\
> \
> Chat with multiple document.\
> \
> Args:\
> &#x20;   knowledge\_base: The knowledge base request payload containing the list of documents and messages.\
> &#x20;   model\_name: The model name.\
> &#x20;   temperature: The model temperature max value is 1.5 and min value is 0.1.\
> &#x20;   stream: Whether to stream the response or not.\
> &#x20;   cite\_source: Whether to cite the source or not.\
> &#x20;   language: The language to respond in.\
> &#x20;   length: The length of the response\
> &#x20;   agent\_mode: Whether to use agent mode or not.\
> &#x20;   user: The current user.\
> \
> Returns:\
> &#x20;   ChatSerializer: The chat response.

```json
{"openapi":"3.1.0","info":{"title":"FastAPI","version":"0.1.0"},"security":[{"APIKeyHeader":[]}],"components":{"securitySchemes":{"APIKeyHeader":{"type":"apiKey","in":"header","name":"X-API-Key"}},"schemas":{"AIModelType":{"type":"string","enum":["CLAUDE1","CLAUDE2","GPT3","GPT4","GPT4O_MINI","GEMINI_FLASH","GEMINI_PRO","GPT5_MINI","GPT5_2","GPT5_NANO","GPT5"],"title":"AIModelType"},"LANGUAGE":{"type":"string","enum":["DEFAULT","ENGLISH","FRENCH","GERMAN","SPANISH","CHINESE","JAPANESE","KOREAN","PORTUGUESE","ARABIC","ITALIAN","TURKISH","HEBREW","DUTCH"],"title":"LANGUAGE"},"ChatResponseLengthChoice":{"type":"string","enum":["SHORT","LONG"],"title":"ChatResponseLengthChoice"},"KnowledgeChatRequest":{"properties":{"documents":{"items":{"type":"string"},"type":"array","title":"Documents"},"messages":{"items":{"$ref":"#/components/schemas/ChatRequest"},"type":"array","title":"Messages"}},"type":"object","required":["documents","messages"],"title":"KnowledgeChatRequest","description":"KnowledgeChatRequest response schema."},"ChatRequest":{"properties":{"sender":{"type":"string","title":"Sender"},"message":{"type":"string","title":"Message"}},"type":"object","required":["sender","message"],"title":"ChatRequest","description":"ChatRequest response schema."},"ChatSerializer":{"properties":{"question":{"$ref":"#/components/schemas/ChatResponse"},"answer":{"$ref":"#/components/schemas/ChatResponse"},"created":{"type":"string","format":"date-time","title":"Created"}},"type":"object","required":["question","answer"],"title":"ChatSerializer"},"ChatResponse":{"properties":{"sender":{"type":"string","title":"Sender"},"message":{"type":"string","title":"Message"},"type":{"type":"string","title":"Type"}},"type":"object","required":["sender","message","type"],"title":"ChatResponse","description":"ChatResponse response schema."},"HTTPValidationError":{"properties":{"detail":{"items":{"$ref":"#/components/schemas/ValidationError"},"type":"array","title":"Detail"}},"type":"object","title":"HTTPValidationError"},"ValidationError":{"properties":{"loc":{"items":{"anyOf":[{"type":"string"},{"type":"integer"}]},"type":"array","title":"Location"},"msg":{"type":"string","title":"Message"},"type":{"type":"string","title":"Error Type"}},"type":"object","required":["loc","msg","type"],"title":"ValidationError"}}},"paths":{"/v1/api/knowledge_base_chat":{"post":{"tags":["chat"],"summary":"Chat With Multiple Documents","description":"[DEPRECATED] Chat with multiple documents using knowledgebase Id.\nPlease use /api/knowledge/{knowledge_base_id}/chat instead.\n\nChat with multiple document.\n\nArgs:\n    knowledge_base: The knowledge base request payload containing the list of documents and messages.\n    model_name: The model name.\n    temperature: The model temperature max value is 1.5 and min value is 0.1.\n    stream: Whether to stream the response or not.\n    cite_source: Whether to cite the source or not.\n    language: The language to respond in.\n    length: The length of the response\n    agent_mode: Whether to use agent mode or not.\n    user: The current user.\n\nReturns:\n    ChatSerializer: The chat response.","operationId":"chat_with_multiple_documents_v1_api_knowledge_base_chat_post","deprecated":true,"parameters":[{"name":"model_name","in":"query","required":false,"schema":{"$ref":"#/components/schemas/AIModelType","default":"GPT5_MINI"}},{"name":"stream","in":"query","required":false,"schema":{"type":"boolean","default":false,"title":"Stream"}},{"name":"cite_source","in":"query","required":false,"schema":{"type":"boolean","default":false,"title":"Cite Source"}},{"name":"temperature","in":"query","required":false,"schema":{"type":"number","default":0.7,"title":"Temperature"}},{"name":"language","in":"query","required":false,"schema":{"$ref":"#/components/schemas/LANGUAGE","default":"DEFAULT"}},{"name":"length","in":"query","required":false,"schema":{"anyOf":[{"$ref":"#/components/schemas/ChatResponseLengthChoice"},{"type":"null"}],"default":"LONG","title":"Length"}},{"name":"agent_mode","in":"query","required":false,"schema":{"type":"boolean","default":true,"title":"Agent Mode"}}],"requestBody":{"required":true,"content":{"application/json":{"schema":{"$ref":"#/components/schemas/KnowledgeChatRequest"}}}},"responses":{"200":{"description":"Successful Response","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ChatSerializer"}}}},"422":{"description":"Validation Error","content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPValidationError"}}}}}}}}}
```

## Query paramters

* `stream` (`boolean`, optional): Flag for streaming. Default is `false`
* model\_name (string, optional) : The model the user chooses to use, model choices includes GPT5\_2, GPT5, GPT5\_MINI, GPT5\_NANO, GEMINI\_FLASH, CLAUDE1, CLAUDE2, GPT4, GPT5, GEMINI\_PRO, GPT4O\_MINI. Default model is GPT5\_2
* agent\_mode (boolean, optional) : Enabled by default. This flag determines whether the system uses our agent to answer your question. When set to `True`, responses may take slightly longer but are generally more accurate and higher quality than those generated in normal mode.
* cite\_source (boolean, optional) :  Flag for cite\_sources. Default if false
* temperature (float, optional) : Flag for temperature. Default is 0.7&#x20;
* 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

```json
{
  "documents": [
    "3c06c3f8-be9f-4f43-ac00-b1a82fd25b30"
  ],
  "messages": [
    // Optional system prompt that can be sent (can be used to specify custom prompts) 
    {
      "sender": "system",
      "message": "Reply to my question in two sentences"
    },
    // Compulsory user message that must be sent in the request
    {
      "sender": "user",
      "message": "What are the documents all about?"
    }
  ]
}
```

## Response:

* 200 : Successful Response
  * question : A dict of information directed to the model

    * sender : The sender of the question,
    * message : The question asked&#x20;
    * 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 &#x20;
    * type : Has a value of "response"

```json
{
  "question": {
    "sender": "user",
    "message": "What is the document all about",
    "type": "question"
  },
  "answer": {
    "sender": "bot",
    "message": "The document simply describes the applications of motions",
    "type": "response"
  },
  "created": "2024-08-23T11:01:46.204541"
}
```

## Examples

```markup
curl -X POST 'https://api.askyourpdf.com/v1/api/knowledge_base_chat?model_name=GPT4O_MINI&stream=false&length=LONG&language=ARABIC&temperature=0.7' \
  -H 'x-api-key: YOUR_API_KEY' \
  -H 'Content-Type: application/json' \
  -d '{
    "documents": [
      "3c06c3f8-be9f-4f43-ac00-b1a82fd25b30"
    ],
    "messages": [
      {
        "sender": "user",
        "message": "What is the document all about"
      }
    ]
  }'
```

```python
import requests

headers = {
    'x-api-key': 'YOUR_API_KEY'
}

payload = {
  "documents": [
    "3c06c3f8-be9f-4f43-ac00-b1a82fd25b30"
  ],
  "messages": [
    {
      "sender": "user",code
      "message": "What is the document all about"
    }
  ]
}

params = {
"model_name":"GPT4O_MINI",
"stream":False,
"length":"LONG",
"language":"ARABIC",
"temperaature":0.7
}

response = requests.post('https://api.askyourpdf.com/v1/api/knowledge_base_chat', 
headers=headers, json=payload, params = params)

if response.status_code == 200:
    print(response.json())
else:
    print('Error:', response.status_code)
```

```javascript
const axios = require('axios');

const headers = {
  'x-api-key': 'YOUR_API_KEY'
};

const payload = {
  "documents": [
    "3c06c3f8-be9f-4f43-ac00-b1a82fd25b30"
  ],
  "messages": [
    {
      "sender": "user",
      "message": "What is the document all about"
    }
  ]
};

const params = {
  "model_name": "GPT4O_MINI",
  "stream": false,
  "length": "LONG",
  "language": "ARABIC",
  "temperature": 0.7
};

axios.post('https://api.askyourpdf.com/v1/api/knowledge_base_chat', payload, {
  headers: headers,
  params: params
})
  .then(response => {
    console.log(response.data);
  })
  .catch(error => {
    console.error('Error:', error.response ? error.response.status : error.message);
  });
```

## 5.  Documents Retrieval Endpoint

This endpoint allows users to retrieve a paginated list of their uploaded documents.

## Fetch Documents

> Fetch all documents for the current user.\
> \
> Returns:\
> &#x20;   dict: A list of documents.

```json
{"openapi":"3.1.0","info":{"title":"FastAPI","version":"0.1.0"},"security":[{"APIKeyHeader":[]}],"components":{"securitySchemes":{"APIKeyHeader":{"type":"apiKey","in":"header","name":"X-API-Key"}},"schemas":{"UserDocumentsMetaSerializer":{"properties":{"total_pages":{"type":"integer","title":"Total Pages","default":0},"documents":{"items":{"$ref":"#/components/schemas/UserDocumentMeta"},"type":"array","title":"Documents"}},"type":"object","required":["documents"],"title":"UserDocumentsMetaSerializer","description":"Serializer for paginated user documents meta data"},"UserDocumentMeta":{"properties":{"name":{"type":"string","title":"Name"},"doc_id":{"type":"string","title":"Doc Id"},"summary":{"anyOf":[{"type":"string"},{"type":"null"}],"title":"Summary"},"language":{"type":"string","title":"Language","default":"en"},"pages":{"type":"integer","title":"Pages","default":0},"shareable":{"type":"boolean","title":"Shareable","default":true},"date_time":{"type":"string","format":"date-time","title":"Date Time"}},"type":"object","required":["name","doc_id"],"title":"UserDocumentMeta"},"HTTPValidationError":{"properties":{"detail":{"items":{"$ref":"#/components/schemas/ValidationError"},"type":"array","title":"Detail"}},"type":"object","title":"HTTPValidationError"},"ValidationError":{"properties":{"loc":{"items":{"anyOf":[{"type":"string"},{"type":"integer"}]},"type":"array","title":"Location"},"msg":{"type":"string","title":"Message"},"type":{"type":"string","title":"Error Type"}},"type":"object","required":["loc","msg","type"],"title":"ValidationError"}}},"paths":{"/v1/api/documents":{"get":{"tags":["document","document"],"summary":"Fetch Documents","description":"Fetch all documents for the current user.\n\nReturns:\n    dict: A list of documents.","operationId":"fetch_documents_v1_api_documents_get","parameters":[{"name":"page","in":"query","required":false,"schema":{"type":"integer","minimum":1,"default":1,"title":"Page"}},{"name":"page_size","in":"query","required":false,"schema":{"type":"integer","maximum":100,"minimum":1,"default":10,"title":"Page Size"}}],"responses":{"200":{"description":"Successful Response","content":{"application/json":{"schema":{"$ref":"#/components/schemas/UserDocumentsMetaSerializer"}}}},"422":{"description":"Validation Error","content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPValidationError"}}}}}}}}}
```

### **Query Parameters:**

* `page` (`integer`, optional): The page to return. Defaults to `1`.
* page\_size (integer, optional): The number of documents to return per page. Defaults to 10.

### **Response:**

* `200` Successful Response
  * `total_pages` (Integer): The total number of pages available for querying
  * `documents` (Array): A list of document details belonging to the user.
    * `name`
    * `doc_id`
    * `summary`
    * `language`
    * `pages`
    * `shareable`
    * `date_time`

```json
{
  "total_pages": 1,
  "documents": [
    {
      "name": "Nature.pdf",
      "doc_id": "6e60e87c-6154-4dff-8e62-ff10d8ed16dd",
      "summary": "This is a document about nature",
      "language": "en",
      "pages": 10,
      "shareable": true,
      "date_time": "2023-07-21T06:18:18.891Z"
    }
  ]
}
```

### **Examples:**

{% code title="cURL" %}

```markup
curl -X GET 
-H 'x-api-key: YOUR_API_KEY' 
'https://api.askyourpdf.com/v1/api/documents?page=1&page_size=10'
```

{% endcode %}

{% code title="Python" %}

```python
import requests

headers = {
    'x-api-key': 'YOUR_API_KEY'
}

params = {
    'page': 1,
    'page_size': 10
}

response = requests.get('https://api.askyourpdf.com/v1/api/documents', 
headers=headers, params=params)

if response.status_code == 200:
    print(response.json())
else:
    print('Error:', response.status_code)

```

{% endcode %}

{% code title="Javascript" %}

```javascript
const axios = require('axios');

const headers = {
    'x-api-key': 'YOUR_API_KEY'
};

const params = {
    'page': 1,
    'page_size': 10
};

axios.get('https://api.askyourpdf.com/v1/api/documents', 
{headers: headers, params: params})
.then((response) => {
  if (response.status === 200) {
    console.log(response.data);
  } else {
    console.log('Error:', response.status);
  }
})
.catch((error) => {
  console.error(error);
});

```

{% endcode %}

##

## 6.  Single Document Retrieval Endpoint

This endpoint allows users to retrieve a single document.

## Fetch Document

> Fetch a user's documents using the doc\_id.\
> \
> Returns:\
> &#x20;   dict: A single document.

```json
{"openapi":"3.1.0","info":{"title":"FastAPI","version":"0.1.0"},"security":[{"APIKeyHeader":[]}],"components":{"securitySchemes":{"APIKeyHeader":{"type":"apiKey","in":"header","name":"X-API-Key"}},"schemas":{"UserDocumentMeta":{"properties":{"name":{"type":"string","title":"Name"},"doc_id":{"type":"string","title":"Doc Id"},"summary":{"anyOf":[{"type":"string"},{"type":"null"}],"title":"Summary"},"language":{"type":"string","title":"Language","default":"en"},"pages":{"type":"integer","title":"Pages","default":0},"shareable":{"type":"boolean","title":"Shareable","default":true},"date_time":{"type":"string","format":"date-time","title":"Date Time"}},"type":"object","required":["name","doc_id"],"title":"UserDocumentMeta"},"HTTPValidationError":{"properties":{"detail":{"items":{"$ref":"#/components/schemas/ValidationError"},"type":"array","title":"Detail"}},"type":"object","title":"HTTPValidationError"},"ValidationError":{"properties":{"loc":{"items":{"anyOf":[{"type":"string"},{"type":"integer"}]},"type":"array","title":"Location"},"msg":{"type":"string","title":"Message"},"type":{"type":"string","title":"Error Type"}},"type":"object","required":["loc","msg","type"],"title":"ValidationError"}}},"paths":{"/v1/api/documents/{doc_id}":{"get":{"tags":["document","document"],"summary":"Fetch Document","description":"Fetch a user's documents using the doc_id.\n\nReturns:\n    dict: A single document.","operationId":"fetch_document_v1_api_documents__doc_id__get","parameters":[{"name":"doc_id","in":"path","required":true,"schema":{"type":"string","title":"Doc Id"}}],"responses":{"200":{"description":"Successful Response","content":{"application/json":{"schema":{"$ref":"#/components/schemas/UserDocumentMeta"}}}},"422":{"description":"Validation Error","content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPValidationError"}}}}}}}}}
```

### **Path Parameters:**

`doc_id` (`string`, required): The ID of the document for the conversation.

### **Response:**

* `200` Successful Response
  * `name`
  * `doc_id`
  * `summary`
  * `language`
  * `pages`
  * `shareable`
  * `date_time`

```json
  {
    "name": "Nature.pdf",
    "doc_id": "6e60e87c-6154-4dff-8e62-ff10d8ed16dd",
    "summary": "This is a document about nature",
    "language": "en",
    "pages": 10,
    "shareable": true,
    "date_time": "2023-07-21T06:18:18.891Z"
  }
```

### **Examples:**

{% code title="cURL" %}

```markup
curl -X GET
 -H 'x-api-key: YOUR_API_KEY' 
 'https://api.askyourpdf.com/v1/api/documents/{YOUR_DOC_ID}'

```

{% endcode %}

{% code title="Python" %}

```python
import requests

headers = {
    'x-api-key': 'YOUR_API_KEY'
}

response = requests.get('https://api.askyourpdf.com/v1/api/documents/{YOUR_DOC_ID}',
 headers=headers)

if response.status_code == 200:
    print(response.json())
else:
    print('Error:', response.status_code)

```

{% endcode %}

{% code title="Javascript" %}

```javascript
const axios = require('axios');

const headers = {
    'x-api-key': 'YOUR_API_KEY'
};

axios.get('https://api.askyourpdf.com/v1/api/documents/{YOUR_DOC_ID}',
 {headers: headers})
.then((response) => {
    if (response.status === 200) {
        console.log(response.data);
    } else {
        console.log('Error:', response.status);
    }
})
.catch((error) => {
    console.error(error);
});

```

{% endcode %}

##

## 7.  Delete Document Endpoint

Allows users to delete a single document

## Delete Document

> Delete a document belonging to the authenticated user.\
> \
> Args:\
> &#x20;   user: The user who is deleting the file.\
> &#x20;   doc\_id: The document ID to delete.\
> \
> Returns:\
> &#x20;   dict: A success message.

```json
{"openapi":"3.1.0","info":{"title":"FastAPI","version":"0.1.0"},"security":[{"APIKeyHeader":[]}],"components":{"securitySchemes":{"APIKeyHeader":{"type":"apiKey","in":"header","name":"X-API-Key"}},"schemas":{"HTTPValidationError":{"properties":{"detail":{"items":{"$ref":"#/components/schemas/ValidationError"},"type":"array","title":"Detail"}},"type":"object","title":"HTTPValidationError"},"ValidationError":{"properties":{"loc":{"items":{"anyOf":[{"type":"string"},{"type":"integer"}]},"type":"array","title":"Location"},"msg":{"type":"string","title":"Message"},"type":{"type":"string","title":"Error Type"}},"type":"object","required":["loc","msg","type"],"title":"ValidationError"}}},"paths":{"/v1/api/documents/{doc_id}":{"delete":{"tags":["document","document"],"summary":"Delete Document","description":"Delete a document belonging to the authenticated user.\n\nArgs:\n    user: The user who is deleting the file.\n    doc_id: The document ID to delete.\n\nReturns:\n    dict: A success message.","operationId":"delete_document_v1_api_documents__doc_id__delete","parameters":[{"name":"doc_id","in":"path","required":true,"schema":{"type":"string","title":"Doc Id"}}],"responses":{"200":{"description":"Successful Response","content":{"application/json":{"schema":{"type":"object","additionalProperties":true,"title":"Response Delete Document V1 Api Documents  Doc Id  Delete"}}}},"422":{"description":"Validation Error","content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPValidationError"}}}}}}}}}
```

### **Path Parameters:**

`doc_id` (`string`, required): The ID of the document to be deleted.

### **Response:**

* `200` Successful Response

<pre class="language-json"><code class="lang-json"><strong> {"message": "Document deleted successfully"}
</strong></code></pre>

### **Examples:**

{% code title="cURL" %}

```markup
curl -X DELETE 
-H 'x-api-key: YOUR_API_KEY' 
'https://api.askyourpdf.com/v1/api/documents/DOC_ID'

```

{% endcode %}

{% code title="Python" %}

```python
import requests

headers = {
    'x-api-key': 'YOUR_API_KEY'
}

response = requests.delete('https://api.askyourpdf.com/v1/api/documents/DOC_ID', headers=headers)

if response.status_code == 200:
    print('Document deleted successfully')
else:
    print('Error:', response.status_code)


```

{% endcode %}

{% code title="Javascript" %}

```javascript
const axios = require('axios');

const headers = {
    'x-api-key': 'YOUR_API_KEY'
};

axios.delete('https://api.askyourpdf.com/v1/api/documents/DOC_ID', {headers: headers})
.then((response) => {
    if (response.status === 200) {
        console.log('Document deleted successfully');
    } else {
        console.log('Error:', response.status);
    }
})
.catch((error) => {
    console.error(error);
});

```

{% endcode %}

## 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)&#x20;
* page\_size (integer, optional)
* order (string optional)

## Response

* &#x20;200 Successful Response
  * total\_pages (Integer): The total number of pages available for querying
  * knowledge\_bases : An array of knowledges bases being queried

```json
{
  "total_pages": 0,
  "knowledge_bases": [
    {
      "knowledge_base_id": "b2cb7d2c-5922-4dad-94b5-65b657e02a9c",
      "name": "Johns knowledgebase",
      "document_details": [
        {
          "doc_id": "b2cb7d2c-5922-4dad-94b5-65b657e02a9c",
          "name": "new_docs.pdf"
        }
      ],
      "date_time": "2024-08-21T12:38:07.085Z"
    }
  ]
}
```

* 422 : Validation Error&#x20;

```json
{
  "detail": [
    {
      "loc": [
        "string",
        0
      ],
      "msg": "string",
      "type": "string"
    }
  ]
}
```

## Examples

{% tabs %}
{% tab title="Curl" %}

```markup
curl -H "x-api-key: YOUR_API_KEY"
     -X GET "https://api.askyourpdf.com/v1/api/knowledge"

```

{% endtab %}

{% tab title="Python" %}

```python

import requests

headers = {
    'x-api-key': 'YOUR_API_KEY'
}

response = requests.get('https://api.askyourpdf.com/v1/api/knowledge', headers=headers)

if response.status_code == 200:
    print(response.json())
else:
    print('Error:', response.status_code)
```

{% endtab %}

{% tab title="Javascript" %}

```javascript
const axios = require('axios');

const headers = {
    'x-api-key': 'YOUR_API_KEY'
};

axios.get('https://api.askyourpdf.com/v1/api/knowledge', { headers })
    .then(response => {
        console.log(response.data);
    })
    .catch(error => {
        console.error('Error:', error.response ? error.response.status : error.message);
    });

```

{% endtab %}
{% endtabs %}

### 9. Create Knowledge Base

This endpoint enables a user to create a knowlege base from the list of document IDs

## Create Knowledge Base

> Create a knowledge base from a list of document IDs.\
> \
> Args:\
> &#x20;   knowledge\_base: The knowledge base to create.\
> &#x20;   user: The user making the request.\
> \
> Returns:\
> &#x20;   KnowledgeBaseResponse: The response containing the knowledge base ID.

```json
{"openapi":"3.1.0","info":{"title":"FastAPI","version":"0.1.0"},"security":[{"APIKeyHeader":[]}],"components":{"securitySchemes":{"APIKeyHeader":{"type":"apiKey","in":"header","name":"X-API-Key"}},"schemas":{"KnowledgeBaseRequest":{"properties":{"name":{"type":"string","title":"Name"},"document_ids":{"items":{"type":"string"},"type":"array","title":"Document Ids"}},"type":"object","required":["name","document_ids"],"title":"KnowledgeBaseRequest"},"KnowledgeBaseResponse":{"properties":{"knowledge_base_id":{"type":"string","title":"Knowledge Base Id"}},"type":"object","required":["knowledge_base_id"],"title":"KnowledgeBaseResponse"},"HTTPValidationError":{"properties":{"detail":{"items":{"$ref":"#/components/schemas/ValidationError"},"type":"array","title":"Detail"}},"type":"object","title":"HTTPValidationError"},"ValidationError":{"properties":{"loc":{"items":{"anyOf":[{"type":"string"},{"type":"integer"}]},"type":"array","title":"Location"},"msg":{"type":"string","title":"Message"},"type":{"type":"string","title":"Error Type"}},"type":"object","required":["loc","msg","type"],"title":"ValidationError"}}},"paths":{"/v1/api/knowledge":{"post":{"tags":["knowledge base"],"summary":"Create Knowledge Base","description":"Create a knowledge base from a list of document IDs.\n\nArgs:\n    knowledge_base: The knowledge base to create.\n    user: The user making the request.\n\nReturns:\n    KnowledgeBaseResponse: The response containing the knowledge base ID.","operationId":"create_knowledge_base_v1_api_knowledge_post","requestBody":{"required":true,"content":{"application/json":{"schema":{"$ref":"#/components/schemas/KnowledgeBaseRequest"}}}},"responses":{"201":{"description":"Successful Response","content":{"application/json":{"schema":{"$ref":"#/components/schemas/KnowledgeBaseResponse"}}}},"422":{"description":"Validation Error","content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPValidationError"}}}}}}}}}
```

### Body

* name \* (string, required) : The name of the knowledgebase
* document\_ids \* (array, required)  : The documents Ids to be included in the knowledgebase

```json
{
  "name": "Johns knowledgebase",
  "document_ids": [
    "b2cb7d2c-5922-4dad-94b5-65b657e02a9c"
  ]
}
```

```
POST /api/knowledge
```

<details>

<summary>Authorization</summary>

API Key

</details>

## Response

* 201 : Successful Response
  * KnowlegeBaseResponse : A dictionary of knowledge\_base\_id created

```json
{
  "knowledge_base_id": "b2cb7d2c-5922-4dad-94b5-65b657e02a9c"
}
```

* 422: Validation Error

```json
{
  "detail": [
    {
      "loc": [
        "string",
        0
      ],
      "msg": "string",
      "type": "string"
    }
  ]
}
```

## Examples

{% tabs %}
{% tab title="Curl" %}
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" ] }'
{% endtab %}

{% tab title="Python" %}

```python
import requests

headers = {
    'x-api-key': 'YOUR_API_KEY'
}

payload = {
  "name": "string",
  "document_ids": [
    "string"
  ]
}
response = requests.post('https://api.askyourpdf.com/v1/api/knowledge', json=payload, headers=headers)

if response.status_code == 201:
    print(response.json())
else:
    print('Error:', response.status_code)
```

{% endtab %}

{% tab title="Javascript" %}

```javascript
const axios = require('axios');

const headers = {
  'x-api-key': 'YOUR_API_KEY'
};

const payload = {
  "name": "string",
  "document_ids": [
    "string"
  ]
};

axios.post('https://api.askyourpdf.com/v1/api/knowledge', payload, { headers })
  .then(response => {
    if (response.status === 201) {
      console.log(response.data);
    } else {
      console.log('Error:', response.status);
    }
  })
  .catch(error => {
    console.error('Error:', error.response ? error.response.status : error.message);
  });
```

{% endtab %}
{% endtabs %}

## 14. Chat With Documents Using Knowledge Base ID

This endpoint enables a user converse with multiple documents by using a single knowledgebase id

## Chat With Knowledgebase

> Chat with multiple documents using knowledgebase Id.\
> \
> Args:\
> &#x20;   knowledge\_base\_chat\_request : The knowledge base chat request payload containing the messages.\
> &#x20;   knowledge\_base\_id: The knowledge id is id of the knowledgebase documents you want to chat with.\
> &#x20;   model\_name: The model name.\
> &#x20;   temperature: The model temperature max value is 1.5 and min value is 0.1.\
> &#x20;   stream: Whether to stream the response or not.\
> &#x20;   cite\_source: Whether to cite the source or not.\
> &#x20;   language: The language to respond in.\
> &#x20;   length: The length of the response\
> &#x20;   agent\_mode: Whether to use agent mode or not.\
> &#x20;   user: The current user.\
> \
> Returns:\
> &#x20;   ChatSerializer: The chat response.

```json
{"openapi":"3.1.0","info":{"title":"FastAPI","version":"0.1.0"},"security":[{"APIKeyHeader":[]}],"components":{"securitySchemes":{"APIKeyHeader":{"type":"apiKey","in":"header","name":"X-API-Key"}},"schemas":{"AIModelType":{"type":"string","enum":["CLAUDE1","CLAUDE2","GPT3","GPT4","GPT4O_MINI","GEMINI_FLASH","GEMINI_PRO","GPT5_MINI","GPT5_2","GPT5_NANO","GPT5"],"title":"AIModelType"},"LANGUAGE":{"type":"string","enum":["DEFAULT","ENGLISH","FRENCH","GERMAN","SPANISH","CHINESE","JAPANESE","KOREAN","PORTUGUESE","ARABIC","ITALIAN","TURKISH","HEBREW","DUTCH"],"title":"LANGUAGE"},"ChatResponseLengthChoice":{"type":"string","enum":["SHORT","LONG"],"title":"ChatResponseLengthChoice"},"KnowledgeBaseIDChatRequest":{"properties":{"messages":{"items":{"$ref":"#/components/schemas/ChatRequest"},"type":"array","title":"Messages"}},"type":"object","required":["messages"],"title":"KnowledgeBaseIDChatRequest","description":"KnowledgeBaseIDChatRequest response schema."},"ChatRequest":{"properties":{"sender":{"type":"string","title":"Sender"},"message":{"type":"string","title":"Message"}},"type":"object","required":["sender","message"],"title":"ChatRequest","description":"ChatRequest response schema."},"ChatSerializer":{"properties":{"question":{"$ref":"#/components/schemas/ChatResponse"},"answer":{"$ref":"#/components/schemas/ChatResponse"},"created":{"type":"string","format":"date-time","title":"Created"}},"type":"object","required":["question","answer"],"title":"ChatSerializer"},"ChatResponse":{"properties":{"sender":{"type":"string","title":"Sender"},"message":{"type":"string","title":"Message"},"type":{"type":"string","title":"Type"}},"type":"object","required":["sender","message","type"],"title":"ChatResponse","description":"ChatResponse response schema."},"HTTPValidationError":{"properties":{"detail":{"items":{"$ref":"#/components/schemas/ValidationError"},"type":"array","title":"Detail"}},"type":"object","title":"HTTPValidationError"},"ValidationError":{"properties":{"loc":{"items":{"anyOf":[{"type":"string"},{"type":"integer"}]},"type":"array","title":"Location"},"msg":{"type":"string","title":"Message"},"type":{"type":"string","title":"Error Type"}},"type":"object","required":["loc","msg","type"],"title":"ValidationError"}}},"paths":{"/v1/api/knowledge/{knowledge_base_id}/chat":{"post":{"tags":["chat"],"summary":"Chat With Knowledgebase","description":"Chat with multiple documents using knowledgebase Id.\n\nArgs:\n    knowledge_base_chat_request : The knowledge base chat request payload containing the messages.\n    knowledge_base_id: The knowledge id is id of the knowledgebase documents you want to chat with.\n    model_name: The model name.\n    temperature: The model temperature max value is 1.5 and min value is 0.1.\n    stream: Whether to stream the response or not.\n    cite_source: Whether to cite the source or not.\n    language: The language to respond in.\n    length: The length of the response\n    agent_mode: Whether to use agent mode or not.\n    user: The current user.\n\nReturns:\n    ChatSerializer: The chat response.","operationId":"chat_with_knowledgebase_v1_api_knowledge__knowledge_base_id__chat_post","parameters":[{"name":"knowledge_base_id","in":"path","required":true,"schema":{"type":"string","title":"Knowledge Base Id"}},{"name":"model_name","in":"query","required":false,"schema":{"$ref":"#/components/schemas/AIModelType","default":"GPT5_2"}},{"name":"stream","in":"query","required":false,"schema":{"type":"boolean","default":false,"title":"Stream"}},{"name":"temperature","in":"query","required":false,"schema":{"type":"number","default":0.7,"title":"Temperature"}},{"name":"language","in":"query","required":false,"schema":{"$ref":"#/components/schemas/LANGUAGE","default":"DEFAULT"}},{"name":"length","in":"query","required":false,"schema":{"anyOf":[{"$ref":"#/components/schemas/ChatResponseLengthChoice"},{"type":"null"}],"default":"LONG","title":"Length"}},{"name":"cite_source","in":"query","required":false,"schema":{"type":"boolean","default":false,"title":"Cite Source"}},{"name":"agent_mode","in":"query","required":false,"schema":{"type":"boolean","default":true,"title":"Agent Mode"}}],"requestBody":{"required":true,"content":{"application/json":{"schema":{"$ref":"#/components/schemas/KnowledgeBaseIDChatRequest"}}}},"responses":{"200":{"description":"Successful Response","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ChatSerializer"}}}},"422":{"description":"Validation Error","content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPValidationError"}}}}}}}}}
```

### Query parameters

* `stream` (`boolean`, optional): Flag for streaming. Default is `false`
* model\_name (string, optional) : The model the user chooses to use, model choices includes GPT4O\_MINI, GEMINI\_FLASH, CLAUDE1, CLAUDE2, GPT4,  GPT5\_NANO, GPT5, GEMINI\_PRO. 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&#x20;
* 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:**

* messages: A list of dictionaries with key value of
  * `sender` (`required`): The sender should be `user` or  (`system`If you want to specify a custom system prompt)
  * `message` (`required`): The chat message content.

**The request body to ask a single question.**

<pre class="language-json"><code class="lang-json">{
<strong> "messages":[
</strong>  // Optional system prompt that can be sent (can be used to specify custom prompts) 
    {
      "sender": "system",
      "message": "Reply to my question in five sentences"
    },
    // Compulsor user message that must be sent in the request
    {
      "sender": "user",
      "message": "What do the documents in the knowledgebase talk about?"
    }
  ]
}
</code></pre>

**To ask a follow-up question and provide the model with context you can send your previous questions and responses in the following format.**

```json
[
    {   
    "sender": "user",
    "message": "What does the document say?"
    },
    {
    "sender": "bot",
    "message": "The document consists of words in different languages expressing gratitude"
     },
   {
    "sender": "user",
    "message": "What is the word expressing gratitude in Spanish?"
    }
]
```

### Response

* 200 : Successful Response

```json
{
  "question": {
    "sender": "user",
    "message": "What is the document all about",
    "type": "question"
  },
  "answer": {
    "sender": "bot",
    "message": "The document simply describes the applications of motions",
    "type": "response"
  },
  "created": "2024-08-23T11:01:46.204541"
}
```

* 422 : Validation Error

```json
{
  "detail": [
    {
      "loc": [
        "string",
        0
      ],
      "msg": "string",
      "type": "string"
    }
  ]
}
```

{% tabs %}
{% tab title="Curl" %}

```
curl -X POST "https://api.askyourpdf.com/v1/api/knowledge/{knowledge_base_id}/chat" \
-H "x-api-key: YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '{
  "messages": [
    {
      "sender": "user",
      "message": "What is the document all about"
    }
  ]
}' \
--data-urlencode "model_name=GPT4O_MINI" \
--data-urlencode "stream=False" \
--data-urlencode "length=LONG" \
--data-urlencode "language=ARABIC" \
--data-urlencode "temperaature=0.7"

```

{% endtab %}

{% tab title="Python" %}

```python
import requests

headers = {
    'x-api-key': 'YOUR_API_KEY'
}

payload = {
  "messages": [
    {
      "sender": "user",
      "message": "What is the document all about"
    }
  ]
}

params = {
"model_name":"GPT3",
"stream":False,
"length":"LONG",
"language":"ARABIC",
"temperaature":0.7
}

response = requests.post('https://api.askyourpdf.com/v1/api/knowledge/{knowledge_base_id}/chat', 
headers=headers, json=payload, params = params)

if response.status_code == 200:
    print(response.json())
else:
    print('Error:', response.status_code)
```

{% endtab %}

{% tab title="Javascript" %}

```javascript
const axios = require('axios');

const headers = {
  'x-api-key': 'YOUR_API_KEY',
  'Content-Type': 'application/json'
};

const payload = {
  messages: [
    {
      sender: "user",
      message: "What is the document all about"
    }
  ]
};

const params = {
  model_name: "GPT3",
  stream: false,
  length: "LONG",
  language: "ARABIC",
  temperaature: 0.7
};

axios.post('https://api.askyourpdf.com/v1/api/knowledge/{knowledge_base_id}/chat', payload, {
  headers: headers,
  params: params
})
.then(response => {
  console.log(response.data);
})
.catch(error => {
  console.error('Error:', error.response.status);
});

```

{% endtab %}
{% endtabs %}

## 10.  Get KnowledgeBase

This endpoint enables a user to retrieve a single knowledge base

## Get Knowledge Base

> Get knowledge base\
> \
> Args:\
> &#x20;   knowledge\_base\_id: The ID of the knowledge base to retrieve.\
> &#x20;   user: The user making the request.\
> \
> Returns:\
> &#x20;   KnowledgeDetailedResponse: The response containing the updated knowledge base.

```json
{"openapi":"3.1.0","info":{"title":"FastAPI","version":"0.1.0"},"security":[{"APIKeyHeader":[]}],"components":{"securitySchemes":{"APIKeyHeader":{"type":"apiKey","in":"header","name":"X-API-Key"}},"schemas":{"KnowledgeDetailedResponse":{"properties":{"knowledge_base_id":{"type":"string","title":"Knowledge Base Id"},"name":{"type":"string","title":"Name"},"document_details":{"items":{"$ref":"#/components/schemas/DocumentDetailsResponse"},"type":"array","title":"Document Details"},"date_time":{"type":"string","format":"date-time","title":"Date Time"}},"type":"object","required":["knowledge_base_id","name","document_details"],"title":"KnowledgeDetailedResponse"},"DocumentDetailsResponse":{"properties":{"doc_id":{"type":"string","title":"Doc Id"},"name":{"anyOf":[{"type":"string"},{"type":"null"}],"title":"Name"}},"type":"object","required":["doc_id"],"title":"DocumentDetailsResponse"},"HTTPValidationError":{"properties":{"detail":{"items":{"$ref":"#/components/schemas/ValidationError"},"type":"array","title":"Detail"}},"type":"object","title":"HTTPValidationError"},"ValidationError":{"properties":{"loc":{"items":{"anyOf":[{"type":"string"},{"type":"integer"}]},"type":"array","title":"Location"},"msg":{"type":"string","title":"Message"},"type":{"type":"string","title":"Error Type"}},"type":"object","required":["loc","msg","type"],"title":"ValidationError"}}},"paths":{"/v1/api/knowledge/{knowledge_base_id}":{"get":{"tags":["knowledge base"],"summary":"Get Knowledge Base","description":"Get knowledge base\n\nArgs:\n    knowledge_base_id: The ID of the knowledge base to retrieve.\n    user: The user making the request.\n\nReturns:\n    KnowledgeDetailedResponse: The response containing the updated knowledge base.","operationId":"get_knowledge_base_v1_api_knowledge__knowledge_base_id__get","parameters":[{"name":"knowledge_base_id","in":"path","required":true,"schema":{"type":"string","title":"Knowledge Base Id"}}],"responses":{"200":{"description":"Successful Response","content":{"application/json":{"schema":{"$ref":"#/components/schemas/KnowledgeDetailedResponse"}}}},"422":{"description":"Validation Error","content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPValidationError"}}}}}}}}}
```

### Path parameter

knowledge\_base\_id \* (string, required)

```
GET /api/knowledge/{knowledge_base_id}
```

<details>

<summary>Authorization</summary>

API Key

</details>

## Response

* 200 : Succesful Response

```json
{
  "knowledge_base_id": "b2cb7d2c-5922-4dad-94b5-65b657e02a9c",
  "name": "askyourpdf",
  "document_details": [
    {
      "doc_id": "b2cb7d2c-5922-4dad-94b5-65b657e02a9c",
      "name": "docs_name.pdf"
    }
  ],
  "date_time": "2024-08-22T15:41:56.723Z"
}
```

* 422  : Validator Error

```json
{
  "detail": [
    {
      "loc": [
        "string",
        0
      ],
      "msg": "string",
      "type": "string"
    }
  ]
}
```

## Examples

{% tabs %}
{% tab title="Curl" %}
curl -X GET '<https://api.askyourpdf.com/v1/api/knowledge/YOUR\\_KNOWLEDGE\\_BASE\\_ID'\\>
-H 'x-api-key: YOUR\_API\_KEY'
{% endtab %}

{% tab title="Python" %}

```python
import requests

headers = {
    'x-api-key': 'YOUR_API_KEY'
}

response = requests.get('https://api.askyourpdf.com/v1/api/knowledge/{knowledge_base_id}', headers=headers)

if response.status_code == 200:
    print(response.json())
else:
    print('Error:', response.status_code)
```

{% endtab %}

{% tab title="Javascript" %}

```javascript
const axios = require('axios');

const headers = {
  'x-api-key': 'YOUR_API_KEY'
};

const knowledgeBaseId = 'YOUR_KNOWLEDGE_BASE_ID';

axios.get(`https://api.askyourpdf.com/v1/api/knowledge/${knowledgeBaseId}`, { headers })
  .then(response => {
    if (response.status === 200) {
      console.log(response.data);
    } else {
      console.log('Error:', response.status);
    }
  })
  .catch(error => {
    console.error('Error:', error.response ? error.response.status : error.message);
  });
```

{% endtab %}
{% endtabs %}

## 11. Update Knowledge Base

This endpoint enables a user to update a knowledge base

## Update Knowledge Base

> Update a knowledge base from a list of document IDs.\
> \
> Args:\
> &#x20;   knowledge\_base\_id: The ID of the knowledge base to update.\
> &#x20;   knowledge\_base: The items to update in the knowledge base.\
> &#x20;   user: The user making the request.\
> \
> Returns:\
> &#x20;   KnowledgeDetailedResponse: The response containing the updated knowledge base.

```json
{"openapi":"3.1.0","info":{"title":"FastAPI","version":"0.1.0"},"security":[{"APIKeyHeader":[]}],"components":{"securitySchemes":{"APIKeyHeader":{"type":"apiKey","in":"header","name":"X-API-Key"}},"schemas":{"KnowledgeBaseUpdate":{"properties":{"name":{"anyOf":[{"type":"string"},{"type":"null"}],"title":"Name"},"document_ids":{"items":{"type":"string"},"type":"array","title":"Document Ids"}},"type":"object","required":["document_ids"],"title":"KnowledgeBaseUpdate"},"KnowledgeDetailedResponse":{"properties":{"knowledge_base_id":{"type":"string","title":"Knowledge Base Id"},"name":{"type":"string","title":"Name"},"document_details":{"items":{"$ref":"#/components/schemas/DocumentDetailsResponse"},"type":"array","title":"Document Details"},"date_time":{"type":"string","format":"date-time","title":"Date Time"}},"type":"object","required":["knowledge_base_id","name","document_details"],"title":"KnowledgeDetailedResponse"},"DocumentDetailsResponse":{"properties":{"doc_id":{"type":"string","title":"Doc Id"},"name":{"anyOf":[{"type":"string"},{"type":"null"}],"title":"Name"}},"type":"object","required":["doc_id"],"title":"DocumentDetailsResponse"},"HTTPValidationError":{"properties":{"detail":{"items":{"$ref":"#/components/schemas/ValidationError"},"type":"array","title":"Detail"}},"type":"object","title":"HTTPValidationError"},"ValidationError":{"properties":{"loc":{"items":{"anyOf":[{"type":"string"},{"type":"integer"}]},"type":"array","title":"Location"},"msg":{"type":"string","title":"Message"},"type":{"type":"string","title":"Error Type"}},"type":"object","required":["loc","msg","type"],"title":"ValidationError"}}},"paths":{"/v1/api/knowledge/{knowledge_base_id}":{"put":{"tags":["knowledge base"],"summary":"Update Knowledge Base","description":"Update a knowledge base from a list of document IDs.\n\nArgs:\n    knowledge_base_id: The ID of the knowledge base to update.\n    knowledge_base: The items to update in the knowledge base.\n    user: The user making the request.\n\nReturns:\n    KnowledgeDetailedResponse: The response containing the updated knowledge base.","operationId":"update_knowledge_base_v1_api_knowledge__knowledge_base_id__put","parameters":[{"name":"knowledge_base_id","in":"path","required":true,"schema":{"type":"string","title":"Knowledge Base Id"}}],"requestBody":{"required":true,"content":{"application/json":{"schema":{"$ref":"#/components/schemas/KnowledgeBaseUpdate"}}}},"responses":{"200":{"description":"Successful Response","content":{"application/json":{"schema":{"$ref":"#/components/schemas/KnowledgeDetailedResponse"}}}},"422":{"description":"Validation Error","content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPValidationError"}}}}}}}}}
```

### 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

```json
{
"name": "new knowledgbebase name",
  "document_ids": [
    "b2cb7d2c-5922-4dad-94b5-65b657e02a9c"
  ]
}
```

```
PUT /api/knowledge/{knowledge_base_id}
```

<details>

<summary>Authorization</summary>

API Key

</details>

## Response

* 200 : Successful Response

```json
{
  "knowledge_base_id": "d2cb3e2c-5922-4dad-94b5-65b657e12a9c",
  "name": "KB1",
  "document_details": [
    {
      "doc_id": "b2cb7d2c-5922-4dad-94b5-65b657e02a9c",
      "name": "wolf_of_wallstreet.pdf"
    }
  ],
  "date_time": "2024-08-22T17:50:12.964Z"
}
```

* 422 : Validator Error

```json
{
  "detail": [
    {
      "loc": [
        "string",
        0
      ],
      "msg": "string",
      "type": "string"
    }
  ]
}
```

## Examples

{% tabs %}
{% tab title="Curl" %}

```markup
curl -X PUT 'https://api.askyourpdf.com/v1/api/knowledge/YOUR_KNOWLEDGE_BASE_ID' \
-H 'x-api-key: YOUR_API_KEY' \
-H 'Content-Type: application/json' \
-d '{
  "name": "string",
  "document_ids": [
    "string"
  ]
}'
```

{% endtab %}

{% tab title="Python" %}

```python
import requests

headers = {
    'x-api-key': 'YOUR_API_KEY'
}

payload  = {
  "name": "string",
  "document_ids": [
    "string"
  ]
}

response = requests.put('https://api.askyourpdf.com/v1/api/knowledge/{knowledge_base_id}', json = payload, headers=headers)

if response.status_code == 200:
    print(response.json())
else:
    print('Error:', response.status_code)
```

{% endtab %}

{% tab title="Javascript" %}

```javascript
const axios = require('axios');

const headers = {
  'x-api-key': 'YOUR_API_KEY'
};

const payload = {
  "name": "string",
  "document_ids": [
    "string"
  ]
};

const knowledgeBaseId = 'YOUR_KNOWLEDGE_BASE_ID';

axios.put(`https://api.askyourpdf.com/v1/api/knowledge/${knowledgeBaseId}`, payload, { headers })
  .then(response => {
    if (response.status === 200) {
      console.log(response.data);
    } else {
      console.log('Error:', response.status);
    }
  })
  .catch(error => {
    console.error('Error:', error.response ? error.response.status : error.message);
  });
```

{% endtab %}
{% endtabs %}

## 12. Delete Knowledge Base

This endpoint enables a user to delete a knowledge base

## Delete Knowledge Base

> Delete knowledge base\
> \
> Args:\
> &#x20;   knowledge\_base\_id: The ID of the knowledge base to delete.\
> &#x20;   user: The user making the request.\
> \
> Returns:\
> &#x20;   dict: The response containing a success message

```json
{"openapi":"3.1.0","info":{"title":"FastAPI","version":"0.1.0"},"security":[{"APIKeyHeader":[]}],"components":{"securitySchemes":{"APIKeyHeader":{"type":"apiKey","in":"header","name":"X-API-Key"}},"schemas":{"HTTPValidationError":{"properties":{"detail":{"items":{"$ref":"#/components/schemas/ValidationError"},"type":"array","title":"Detail"}},"type":"object","title":"HTTPValidationError"},"ValidationError":{"properties":{"loc":{"items":{"anyOf":[{"type":"string"},{"type":"integer"}]},"type":"array","title":"Location"},"msg":{"type":"string","title":"Message"},"type":{"type":"string","title":"Error Type"}},"type":"object","required":["loc","msg","type"],"title":"ValidationError"}}},"paths":{"/v1/api/knowledge/{knowledge_base_id}":{"delete":{"tags":["knowledge base"],"summary":"Delete Knowledge Base","description":"Delete knowledge base\n\nArgs:\n    knowledge_base_id: The ID of the knowledge base to delete.\n    user: The user making the request.\n\nReturns:\n    dict: The response containing a success message","operationId":"delete_knowledge_base_v1_api_knowledge__knowledge_base_id__delete","parameters":[{"name":"knowledge_base_id","in":"path","required":true,"schema":{"type":"string","title":"Knowledge Base Id"}}],"responses":{"200":{"description":"Successful Response","content":{"application/json":{"schema":{}}}},"422":{"description":"Validation Error","content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPValidationError"}}}}}}}}}
```

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)

```
DELETE /api/knowledge/{knowledge_base_id}
```

<details>

<summary>Authorization</summary>

API Key

</details>

## Response

* 200 : Successful Response

```json
{"message": "Knowledge base deleted successfully"}

```

## Examples

{% tabs %}
{% tab title="Curl" %}
curl -X DELETE '<https://api.askyourpdf.com/v1/api/knowledge/YOUR\\_KNOWLEDGE\\_BASE\\_ID'\\>
-H 'x-api-key: YOUR\_API\_KEY'
{% endtab %}

{% tab title="Python" %}

```python
import requests

headers = {
'x-api-key': 'YOUR_API_KEY'
}

response = requests.delete('https://api.askyourpdf.com/v1/api/knowledge/{knowledge_base_id}', headers=headers)
if response.status_code == 200:
    print(response.json())
else:
    print('Error:', response.status_code)
```

{% endtab %}

{% tab title="Javascript" %}

```javascript
const axios = require('axios');

const headers = {
  'x-api-key': 'YOUR_API_KEY'
};

const knowledgeBaseId = 'YOUR_KNOWLEDGE_BASE_ID';

axios.delete(`https://api.askyourpdf.com/v1/api/knowledge/${knowledgeBaseId}`, { headers })
  .then(response => {
    if (response.status === 200) {
      console.log(response.data);
    } else {
      console.log('Error:', response.status);
    }
  })
  .catch(error => {
    console.error('Error:', error.response ? error.response.status : error.message);
  });
```

{% endtab %}
{% endtabs %}

## 13.  Search Knowledge Base

This endpoint  retrieves a list of  knowledgebases based on a user's query

## Search Knowledge Bases

> Search knowledge bases\
> \
> Args:\
> &#x20;   query: The search query\
> &#x20;   user: The user making the request.\
> \
> Returns:\
> &#x20;   PaginatedKnowledgeBase: The response containing the updated knowledge base.

```json
{"openapi":"3.1.0","info":{"title":"FastAPI","version":"0.1.0"},"security":[{"APIKeyHeader":[]}],"components":{"securitySchemes":{"APIKeyHeader":{"type":"apiKey","in":"header","name":"X-API-Key"}},"schemas":{"KnowledgeDetailedResponse":{"properties":{"knowledge_base_id":{"type":"string","title":"Knowledge Base Id"},"name":{"type":"string","title":"Name"},"document_details":{"items":{"$ref":"#/components/schemas/DocumentDetailsResponse"},"type":"array","title":"Document Details"},"date_time":{"type":"string","format":"date-time","title":"Date Time"}},"type":"object","required":["knowledge_base_id","name","document_details"],"title":"KnowledgeDetailedResponse"},"DocumentDetailsResponse":{"properties":{"doc_id":{"type":"string","title":"Doc Id"},"name":{"anyOf":[{"type":"string"},{"type":"null"}],"title":"Name"}},"type":"object","required":["doc_id"],"title":"DocumentDetailsResponse"},"HTTPValidationError":{"properties":{"detail":{"items":{"$ref":"#/components/schemas/ValidationError"},"type":"array","title":"Detail"}},"type":"object","title":"HTTPValidationError"},"ValidationError":{"properties":{"loc":{"items":{"anyOf":[{"type":"string"},{"type":"integer"}]},"type":"array","title":"Location"},"msg":{"type":"string","title":"Message"},"type":{"type":"string","title":"Error Type"}},"type":"object","required":["loc","msg","type"],"title":"ValidationError"}}},"paths":{"/v1/api/search/knowledge":{"get":{"tags":["knowledge base"],"summary":"Search Knowledge Bases","description":"Search knowledge bases\n\nArgs:\n    query: The search query\n    user: The user making the request.\n\nReturns:\n    PaginatedKnowledgeBase: The response containing the updated knowledge base.","operationId":"search_knowledge_bases_v1_api_search_knowledge_get","parameters":[{"name":"query","in":"query","required":true,"schema":{"type":"string","title":"Query"}}],"responses":{"200":{"description":"Successful Response","content":{"application/json":{"schema":{"type":"array","items":{"$ref":"#/components/schemas/KnowledgeDetailedResponse"},"title":"Response Search Knowledge Bases V1 Api Search Knowledge Get"}}}},"422":{"description":"Validation Error","content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPValidationError"}}}}}}}}}
```

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)

```
GET /api/search/knowledge
```

<details>

<summary>Authorization</summary>

API Key

</details>

## Response

* 200 : Successful Response

```json
[
  {
    "knowledge_base_id": "string",
    "name": "string",
    "document_details": [
      {
        "doc_id": "string",
        "name": "string"
      }
    ],
    "date_time": "2024-08-22T19:27:28.485Z"
  }
]
```

* 422 : Validator Error

```json
{
  "detail": [
    {
      "loc": [
        "string",
        0
      ],
      "msg": "string",
      "type": "string"
    }
  ]
}
```

## Examples

{% tabs %}
{% tab title="Curl" %}
curl -X GET '<https://api.askyourpdf.com/v1/api/search/knowledge?query=YOUR\\_QUERY'\\>
-H 'x-api-key: YOUR\_API\_KEY'
{% endtab %}

{% tab title="Python" %}

```python
import requests

headers = {
'x-api-key': 'YOUR_API_KEY'
}

response = requests.get('https://api.askyourpdf.com/v1/api/search/knowledge?query={QUERY}', headers=headers)
if response.status_code == 200:
    print(response.json())
else:
    print('Error:', response.status_code)
```

{% endtab %}

{% tab title="Javascript" %}

```javascript
const axios = require('axios');

const headers = {
  'x-api-key': 'YOUR_API_KEY'
};

const query = 'YOUR_QUERY';

axios.get(`https://api.askyourpdf.com/v1/api/search/knowledge?query=${query}`, { headers })
  .then(response => {
    if (response.status === 200) {
      console.log(response.data);
    } else {
      console.log('Error:', response.status);
    }
  })
  .catch(error => {
    console.error('Error:', error.response ? error.response.status : error.message);
  });
```

{% endtab %}
{% endtabs %}

## Models

## 15.  Get Models

This endpoint returns the list of all available models we support on the AskYourPDF API

## GET /v1/api/models

> Get Models

```json
{"openapi":"3.1.0","info":{"title":"FastAPI","version":"0.1.0"},"security":[{"APIKeyHeader":[]}],"components":{"securitySchemes":{"APIKeyHeader":{"type":"apiKey","in":"header","name":"X-API-Key"}},"schemas":{"AIModelsSerializer":{"properties":{"name":{"anyOf":[{"type":"string"},{"type":"null"}],"title":"Name"},"max_tokens":{"anyOf":[{"type":"integer"},{"type":"null"}],"title":"Max Tokens"},"is_paid_model":{"anyOf":[{"type":"boolean"},{"type":"null"}],"title":"Is Paid Model"},"model_provider_name":{"anyOf":[{"type":"string"},{"type":"null"}],"title":"Model Provider Name"}},"type":"object","title":"AIModelsSerializer"}}},"paths":{"/v1/api/models":{"get":{"tags":["models"],"summary":"Get Models","operationId":"get_models_v1_api_models_get","responses":{"200":{"description":"Successful Response","content":{"application/json":{"schema":{"items":{"$ref":"#/components/schemas/AIModelsSerializer"},"type":"array","title":"Response Get Models V1 Api Models Get"}}}}}}}}}
```

Returns:

A list  of all available models each containing&#x20;

* name&#x20;
* max\_tokens
* is\_paid\_model
* model\_provider\_name

## Response

* 200: Successful Response

```json
[
  {
    "name": "GPT4",
    "max_tokens": 3600,
    "is_paid_model": true,
    "model_provider_name": "gpt-4"
  },
  {
    "name": "Claude 1",
    "max_tokens": 4096,
    "is_paid_model": true,
    "model_provider_name": "claude-sonnet-4-5"
  },
  {
    "name": "Claude 2",
    "max_tokens": 4096,
    "is_paid_model": true,
    "model_provider_name": "claude-opus-4-1"
  },
  {
    "name": "GPT4O_MINI",
    "max_tokens": 3600,
    "is_paid_model": false,
    "model_provider_name": "gpt-4o-mini"
  },
  {
    "name": "GEMINI 2.5 PRO",
    "max_tokens": 15000,
    "is_paid_model": true,
    "model_provider_name": "gemini-2.5-pro"
  },
  {
    "name": "GEMINI 2.5 FLASH",
    "max_tokens": 15000,
    "is_paid_model": false,
    "model_provider_name": "gemini-2.5-flash"
  },
  {
    "name": "GPT5",
    "max_tokens": 3600,
    "is_paid_model": true,
    "model_provider_name": "gpt-5"
  },
  {
    "name": "GPT5_NANO",
    "max_tokens": 3600,
    "is_paid_model": false,
    "model_provider_name": "gpt-5-nano"
  }
]
```

{% tabs %}
{% tab title="Curl" %}
curl -X POST "<https://api.askyourpdf.com/v1/api/models"\\>
-H "x-api-key: YOUR\_API\_KEY"
{% endtab %}
{% endtabs %}
