Introduction
Welcome to RagAPI Docs! API Endpoint: https://api.ragapi.org/ (opens in a new tab)
What is RagAPI?
RagAPI is an API for Retrieval Augmented Generation. Currently we support one endpoint /question
where you can ask any document .PDF or .TXT a question.
With RagAPI you can easily build sites like https://pdf.ai/ (opens in a new tab) with only 1 API
Getting Started
API Documentation (opens in a new tab)
import requests
from requests_toolbelt.multipart.encoder import MultipartEncoder
def fetchAnswerFromAPI(question, rawFile):
try:
url = 'https://api.ragapi.org/question'
headers = {
'Authorization': 'Bearer YOUR_RAGAPI_KEY',
}
multipart_data = MultipartEncoder(
fields={
'file': ('file', rawFile),
'question': question,
'openai_key': 'YOUR_OPENAI_KEY',
}
)
headers['Content-Type'] = multipart_data.content_type
response = requests.post(url, headers=headers, data=multipart_data)
if not response.ok:
raise Exception(f'API request failed with status {response.status_code}')
json_data = response.json()
if 'answer' in json_data:
return json_data['answer']
else:
return 'No answer found for this question.'
except Exception as error:
print('API request failed:', error)
return 'Failed to retrieve an answer. Please try again.'