\n {{ $t('hero.subtitle') }}\n
\n\n \n{{ $t('features.subtitle') }}
\n\n {{ $t('whatIs.subtitle') }}\n
\n \n{{ $t(item.descriptionKey) }}
\n\nLearn how to integrate and use Shadai RAG
\n\nimport requests\nimport json\n\n# Base URL\nBASE_URL = \"https://api.shadai.ai\"\n\n# 1. Get a valid token for the API key\ndef get_auth_token(api_key):\n response = requests.post(\n f\"{BASE_URL}/get_valid_token\",\n json={\"api_key\": api_key}\n )\n return response.json() \n\n# 2. Create an account \ndef create_account():\n response = requests.post(\n f\"{BASE_URL}/accounts\",\n json={\"role\": \"developer\"}\n )\n return response.json()\n\n# 3. Create a session\ndef create_session(auth_token):\n headers = {\"Authorization\": f\"Bearer {auth_token}\"}\n response = requests.post(\n f\"{BASE_URL}/sessions\",\n headers=headers\n )\n return response.json()\n\n# 4. Upload a document\ndef upload_document(session_id, file_path, auth_token):\n headers = {\"Authorization\": f\"Bearer {auth_token}\"}\n \n # First, get presigned URL\n filename = file_path.split(\"/\")[-1]\n presigned_url = requests.get(\n f\"{BASE_URL}/sessions/{session_id}/docs/presigned_url\",\n params={\"file_name\": filename},\n headers=headers\n ).json()[\"url\"]\n \n # Then upload the file\n with open(file_path, \"rb\") as f:\n requests.put(presigned_url, data=f)\n \n return \"Document uploaded successfully\"\n\n# 5. Query the document\ndef query_document(session_id, thread_id, query_text, auth_token):\n headers = {\"Authorization\": f\"Bearer {auth_token}\"}\n response = requests.post(\n f\"{BASE_URL}/sessions/{session_id}/threads/{thread_id}/response\",\n json={\"query\": query_text},\n headers=headers\n )\n return response.json()\n\n# Usage example\ndef main():\n api_key = \"your-api-key\"\n # Create account and get credentials\n account = create_account()\n auth_token = get_auth_token(api_key)\n \n # Create a new session\n session = create_session(auth_token)\n session_id = session[\"session_id\"]\n \n # Upload a document\n upload_document(\n session_id=session_id,\n file_path=\"./example.pdf\",\n auth_token=auth_token\n )\n \n # Create thread and query\n thread = requests.post(\n f\"{BASE_URL}/sessions/{session_id}/threads\",\n headers={\"Authorization\": f\"Bearer {auth_token}\"}\n ).json()\n \n # Make a query\n response = query_document(\n session_id=session_id,\n thread_id=thread[\"thread_id\"],\n query_text=\"What are the main points in the document?\",\n auth_token=auth_token\n )\n \n print(json.dumps(response, indent=2))\n\nif __name__ == \"__main__\":\n main()\n
To use Shadai RAG, you'll need an API key. You can get one by:
\nPOST /api/v1/documents
\n Upload documents to your Shadai RAG instance.
\nPOST /api/v1/query
\n Query your documents using natural language.
\nPOST /accounts
\n Create a new developer account.
\n{\n \"role\": \"developer\"\n}\n
GET /accounts
\n Retrieve account information.
\nPOST /sessions
\n Create a new chat session.
\nGET /sessions
\n Retrieve all sessions for the authenticated user.
\nGET /sessions/:session_id/docs
\n Retrieve all documents in a session.
\nGET /sessions/:session_id/docs/presigned_url?file_name={filename}
\n Get a presigned URL for document upload.
\nPOST /sessions/:session_id/threads
\n Create a new conversation thread.
\nPOST /sessions/:session_id/threads/:thread_id/response
\n Generate an AI response to a query.
\n{\n \"query\": \"Your question here\"\n}\n
DELETE /sessions/:session_id/threads/:thread_id
\n Delete a conversation thread.
\n