Chat Completions
Chat completions is the most commonly used interface and is fully compatible with the OpenAI protocol.
POST https://api.4allapi.com/v1/chat/completionsRequest Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
model | string | Yes | Model name, see Model Overview |
messages | array | Yes | Array of conversation messages; each item includes role and content |
stream | boolean | No | Whether to return streamed output, see Streaming Output |
temperature | number | No | Sampling temperature 0–2; higher values produce more diverse output |
top_p | number | No | Nucleus sampling threshold; adjust it as an alternative to temperature |
max_tokens | number | No | Maximum number of tokens in the reply |
stop | string/array | No | Stop words |
presence_penalty | number | No | Topic novelty penalty -2–2 |
frequency_penalty | number | No | Repetition penalty -2–2 |
tools | array | No | Tool/function call definitions (supported models) |
response_format | object | No | For example {"type":"json_object"} forces JSON output |
The role in messages supports system / user / assistant / tool.
content can be a string, or a multimodal array (text + image, see Vision Understanding).
Request Example
curl https://api.4allapi.com/v1/chat/completions \ -H "Content-Type: application/json" \ -H "Authorization: Bearer $AIPROXY_KEY" \ -d '{ "model": "fable-5", "messages": [ {"role": "system", "content": "You are a rigorous technical assistant"}, {"role": "user", "content": "Explain what an API gateway is in one sentence"} ], "temperature": 0.7, "max_tokens": 512 }'Response Structure
{ "id": "chatcmpl-xxx", "object": "chat.completion", "created": 1750000000, "model": "fable-5", "choices": [ { "index": 0, "message": { "role": "assistant", "content": "The API gateway is..." }, "finish_reason": "stop" } ], "usage": { "prompt_tokens": 32, "completion_tokens": 41, "total_tokens": 73 }}The usage field is the basis for billing; see Billing and Credits.