1. Install the OpenAI SDK
pip install openai
npm install openai
2. Generate Your First Image
from openai import OpenAI
client = OpenAI(
api_key="YOUR_EACHLABS_API_KEY",
base_url="https://eachsense-agent.core.eachlabs.run/v1"
)
response = client.chat.completions.create(
model="eachsense/beta",
messages=[{
"role": "user",
"content": "Generate a cyberpunk cityscape at night with neon lights"
}],
stream=False
)
print(response.choices[0].message.content)
# Access generated media URLs
print(response.generations)
import OpenAI from "openai";
const client = new OpenAI({
apiKey: "YOUR_EACHLABS_API_KEY",
baseURL: "https://eachsense-agent.core.eachlabs.run/v1",
});
const response = await client.chat.completions.create({
model: "eachsense/beta",
messages: [
{
role: "user",
content: "Generate a cyberpunk cityscape at night with neon lights",
},
],
stream: false,
});
console.log(response.choices[0].message.content);
console.log(response.generations);
curl -X POST https://eachsense-agent.core.eachlabs.run/v1/chat/completions \
-H "Content-Type: application/json" \
-H "X-API-Key: YOUR_EACHLABS_API_KEY" \
-d '{
"messages": [{"role": "user", "content": "Generate a cyberpunk cityscape at night"}],
"stream": false
}'
3. Stream Responses
Enable streaming to get real-time updates:stream = client.chat.completions.create(
model="eachsense/beta",
messages=[{"role": "user", "content": "Create a 5-second video of ocean waves"}],
stream=True
)
for chunk in stream:
if chunk.choices[0].delta.content:
print(chunk.choices[0].delta.content, end="", flush=True)
4. Multi-Turn Conversation
Usesession_id to maintain context:
import requests
import json
SESSION_ID = "my-first-session"
HEADERS = {
"Content-Type": "application/json",
"X-API-Key": "YOUR_API_KEY"
}
URL = "https://eachsense-agent.core.eachlabs.run/v1/chat/completions"
# Turn 1: Generate an image
requests.post(URL, headers=HEADERS, json={
"messages": [{"role": "user", "content": "Generate a portrait photo"}],
"session_id": SESSION_ID,
"stream": False
})
# Turn 2: Modify it (agent remembers the previous generation)
requests.post(URL, headers=HEADERS, json={
"messages": [{"role": "user", "content": "Now make it anime style"}],
"session_id": SESSION_ID,
"stream": False
})
Next Steps
- Learn about streaming event types
- Explore behavior modes (
agent,plan,ask) - Build workflows with natural language
- Manage sessions for conversation continuity