All requests to the Meibel AI API require authentication using your API key. You’ll need to include this key in the Authorization header of your requests.
# Store your API key in an environment variable (recommended)export MEIBEL_API_KEY="your_api_key_here"# Make a test request to list datasourcescurl -X GET "https://api.meibel.ai/v1/datasources" \ -H "Authorization: Bearer $MEIBEL_API_KEY" \ -H "Content-Type: application/json"
# Replace YOUR_DATASOURCE_ID with the ID from the previous responsecurl -X POST "https://api.meibel.ai/v1/datasources/YOUR_DATASOURCE_ID/dataelements" \ -H "Authorization: Bearer $MEIBEL_API_KEY" \ -H "Content-Type: application/json" \ -d '{ "name": "API Overview", "content": "The Meibel AI API provides several endpoints for managing data and running AI completions. The main endpoints include /datasources, /completions, and /experiences.", "metadata": { "category": "documentation", "section": "api" } }'
For longer responses or real-time interactions, you can use streaming:
# Stream a completionstream = client.rag.chat_stream( messages=[ {"role": "user", "content": "Explain how the Meibel AI confidence scoring works"} ], datasource_ids=[datasource_id], confidence_threshold=0.7)# Process the streamfor chunk in stream: if chunk.choices and len(chunk.choices) > 0 and chunk.choices[0].delta.content: print(chunk.choices[0].delta.content, end="", flush=True)