Send Message Simple API is the quickest way to interact with Onyx programmatically.This endpoint has fewer required parameters and responds with a minimal set of information such as the AI’s answer and a list of the top documents.
You must specify either a chat_session_id or a persona_id in your request.
Copy
Ask AI
import requestsAPI_BASE_URL = "https://cloud.onyx.app/api" # or your own domainAPI_KEY = "YOUR_KEY_HERE"headers = { "Authorization": f"Bearer {API_KEY}", "Content-Type": "application/json"}'''- To create a chat session, see the Full-featured Chat Flow guide below.- To find your persona_id, see the List Agents endpoint in the Agents API Reference.'''response = requests.post( f"{API_BASE_URL}/chat/send-message-simple-api", headers=headers, json={ "message": "What is Onyx?", "persona_id": "0" # The default Onyx Search Assistant })answer = response.json()["answer"]chat_session_id = response.json()["chat_session_id"] # Save this to continue the conversationtop_documents = [ { "id": doc["document_id"], "title": doc["semantic_identifier"], "link": doc["link"] } for doc in response.json()["top_documents"]] # Parse important information from the resultsprint(f"Answer: {answer}")print(f"Top Documents: {top_documents[:5]}") # Print top 5 documents