Chat Completions
Generate text responses based on a conversation history.
POST /v1/chat/completions
Creates a model response for the given chat conversation. The request and response schemas are strictly compatible with the OpenAI API format.
Request Body Parameters
model(string, required): ID of the model to use (e.g.,anthropic/claude-sonnet-4).messages(array, required): A list of messages comprising the conversation so far. Each message requires arole(system, user, assistant) andcontent.temperature(number, optional): What sampling temperature to use, between 0 and 2. Defaults to 1.max_tokens(integer, optional): The maximum number of tokens that can be generated in the chat completion.stream(boolean, optional): If set, partial message deltas will be sent, like in ChatGPT. Tokens will be sent as data-only server-sent events.
Example Request (cURL)
bash
curl https://api.inferhood.xyz/v1/chat/completions \
-H "Content-Type: application/json" \
-H "Authorization: Bearer $INFERHOOD_API_KEY" \
-d '{
"model": "openai/gpt-4o",
"messages": [
{
"role": "system",
"content": "You are a helpful assistant."
},
{
"role": "user",
"content": "Write a haiku about APIs."
}
]
}'Example Request (Python)
python
from openai import OpenAI
import os
client = OpenAI(
api_key=os.environ.get("INFERHOOD_API_KEY"),
base_url="https://api.inferhood.xyz/v1",
)
chat_completion = client.chat.completions.create(
messages=[
{
"role": "user",
"content": "Write a haiku about APIs.",
}
],
model="openai/gpt-4o",
)Response Format
json
{
"id": "chatcmpl-123",
"object": "chat.completion",
"created": 1677652288,
"model": "openai/gpt-4o",
"system_fingerprint": "fp_44709d6fcb",
"choices": [{
"index": 0,
"message": {
"role": "assistant",
"content": "Requests flow swiftly,\nData connects our systems,\nServers quietly hum."
},
"logprobs": null,
"finish_reason": "stop"
}],
"usage": {
"prompt_tokens": 15,
"completion_tokens": 18,
"total_tokens": 33
}
}