Basic Examples¶
Quick-start examples for common API operations.
Chat Completion¶
import requests
response = requests.post(
"https://api.indoxhub.com/api/v1/chat/completions",
headers={"Authorization": "Bearer YOUR_API_KEY"},
json={
"model": "openai/gpt-4o-mini",
"messages": [
{"role": "system", "content": "You are a helpful assistant."},
{"role": "user", "content": "What is machine learning?"}
]
}
)
print(response.json()["data"])
const response = await fetch("https://api.indoxhub.com/api/v1/chat/completions", {
method: "POST",
headers: {
"Authorization": "Bearer YOUR_API_KEY",
"Content-Type": "application/json"
},
body: JSON.stringify({
model: "openai/gpt-4o-mini",
messages: [
{ role: "system", content: "You are a helpful assistant." },
{ role: "user", content: "What is machine learning?" }
]
})
});
console.log((await response.json()).data);
Text Embedding¶
import requests
response = requests.post(
"https://api.indoxhub.com/api/v1/embeddings",
headers={"Authorization": "Bearer YOUR_API_KEY"},
json={
"model": "openai/text-embedding-3-small",
"text": "IndoxHub provides unified AI access."
}
)
vector = response.json()["data"][0]
print(f"Embedding dimensions: {response.json()['dimensions']}")
Image Generation¶
import requests
response = requests.post(
"https://api.indoxhub.com/api/v1/images/generations",
headers={"Authorization": "Bearer YOUR_API_KEY"},
json={
"model": "openai/dall-e-3",
"prompt": "A futuristic city skyline at night, cyberpunk style",
"size": "1024x1024"
}
)
print(response.json()["data"][0]["url"])
Text-to-Speech¶
import requests
response = requests.post(
"https://api.indoxhub.com/api/v1/audio/tts/generations",
headers={"Authorization": "Bearer YOUR_API_KEY"},
json={
"model": "openai/tts-1",
"input": "Hello from IndoxHub!",
"voice": "nova"
}
)
print(response.json()["data"])
Speech-to-Text¶
import requests
with open("audio.mp3", "rb") as f:
response = requests.post(
"https://api.indoxhub.com/api/v1/audio/stt/transcriptions",
headers={"Authorization": "Bearer YOUR_API_KEY"},
files={"file": ("audio.mp3", f, "audio/mpeg")},
data={"model": "openai/whisper-1"}
)
print(response.json()["data"]["text"])