Chat Completions
Generate text responses from any supported model using the OpenAI-compatible chat completions endpoint.
Endpoint
POST https://api.aihubspot.app/v1/chat/completions
Fully OpenAI-compatible. Use the OpenAI SDK by setting base_url to https://api.aihubspot.app/v1.
Request body
| Parameter | Type | Required | Description |
|---|---|---|---|
model | string | Yes | Model ID (e.g. gpt-4o, claude-3-5-sonnet) |
messages | array | Yes | Array of message objects |
stream | boolean | No | Enable SSE streaming (default: false) |
max_tokens | integer | No | Maximum tokens to generate |
temperature | number | No | Sampling temperature 0–2 |
Example
from openai import OpenAI
client = OpenAI(
api_key="AH_SMKRPA_YOUR_KEY",
base_url="https://api.aihubspot.app/v1",
)
response = client.chat.completions.create(
model="claude-3-5-sonnet",
messages=[{"role": "user", "content": "Hello"}],
)
print(response.choices[0].message.content)import OpenAI from 'openai';
const client = new OpenAI({
apiKey: process.env.AH_API_KEY,
baseURL: 'https://api.aihubspot.app/v1',
});
const response = await client.chat.completions.create({
model: 'claude-3-5-sonnet',
messages: [{ role: 'user', content: 'Hello' }],
});
console.log(response.choices[0].message.content);curl https://api.aihubspot.app/v1/chat/completions \
-H "Authorization: Bearer $AH_API_KEY" \
-H "Content-Type: application/json" \
-d '{"model":"claude-3-5-sonnet","messages":[{"role":"user","content":"Hello"}]}'Streaming
with client.chat.completions.create(
model="gpt-4o",
messages=[{"role": "user", "content": "Tell me a story"}],
stream=True,
) as stream:
for chunk in stream:
print(chunk.choices[0].delta.content or "", end="", flush=True)const stream = await client.chat.completions.create({
model: 'gpt-4o',
messages: [{ role: 'user', content: 'Tell me a story' }],
stream: true,
});
for await (const chunk of stream) {
process.stdout.write(chunk.choices[0]?.delta?.content ?? '');
}Drop-in replacement for the OpenAI API. Any library or framework that works with OpenAI works here — just change base_url.