Prerequisites
Before you begin, make sure you have:
- A Meibel AI account (sign up at console.meibel.ai if you don’t have one)
- An API key (generated from the Console under Settings > API Keys)
- Python 3.9+ (if using the Python SDK)
- Basic knowledge of API requests
Step 1: Set Up Authentication
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 datasources
curl -X GET "https://api.meibel.ai/v1/datasources" \
-H "Authorization: Bearer $MEIBEL_API_KEY" \
-H "Content-Type: application/json"
Step 2: Create a Datasource
Datasources are containers for your data elements. Let’s create a datasource for our project:
curl -X POST "https://api.meibel.ai/v1/datasources" \
-H "Authorization: Bearer $MEIBEL_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"name": "Product Documentation",
"description": "Documentation for our product features and APIs"
}'
Step 3: Add a Data Element
Now, let’s add some content to our datasource:
# Replace YOUR_DATASOURCE_ID with the ID from the previous response
curl -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"
}
}'
Step 4: Run a Completion
Now, let’s use our datasource to power a completion with context retrieval:
curl -X POST "https://api.meibel.ai/v1/completions" \
-H "Authorization: Bearer $MEIBEL_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"messages": [
{"role": "user", "content": "What are the main endpoints in your API?"}
],
"datasource_ids": ["YOUR_DATASOURCE_ID"],
"confidence_threshold": 0.7,
"execution_control": {
"enable_tracing": true
}
}'
Step 5: Stream a Response
For longer responses or real-time interactions, you can use streaming:
# Stream a completion
stream = 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 stream
for 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)
Next Steps
Congratulations! You’ve successfully made your first requests to the Meibel AI API. Here are some next steps to explore:
Remember to secure your API keys and follow best practices for rate limiting and error handling in your production applications.