Chat completions
The main endpoint and its parameters.
Request
POST /v1/chat/completions with a JSON body. The request and response format follows the common chat-completions convention, so familiar HTTP clients and libraries work with it. Unknown fields are ignored.
| Parameter | Type | Description |
|---|---|---|
model | string, required | A model id from /v1/models, or auto for the default model. |
messages | list, required | The conversation so far, oldest first. Each message has a role (system, developer, user or assistant) and content. |
max_tokens / max_completion_tokens | integer | The longest answer to produce, in tokens (small pieces of text, roughly a short word or part of a word). Up to 8192. |
temperature | number, 0 to 2 | How random the answer is. Lower, such as 0.2, gives more precise and repeatable answers; higher, such as 1, gives more varied ones. |
top_p | number, 0 to 1 | An alternative way to limit randomness: only the most likely words that add up to this share of probability are considered. Change either this or temperature, not both. |
stop | string or list | Up to 4 strings; the answer ends before the first one it would produce. |
stream | boolean | Send the answer in chunks as it is written; see Streaming. |
stream_options.include_usage | boolean | In a stream, also send usage in the last chunk. |
n | integer | Must be 1: one answer per request. |
A message's content can be plain text or a list of text and image_url parts. Only a model with supports_vision accepts an image, and it must be sent inline as a base64 data: URL.
import os import requests reply = requests.post( "https://api.hoveydai.ir/v1/chat/completions", headers={"Authorization": f"Bearer {os.environ['HOVEYDAI_API_KEY']}"}, json={ "model": "MODEL_ID", "messages": [ {"role": "system", "content": "Answer briefly."}, {"role": "user", "content": "What is a token?"}, ], "max_tokens": 300, "temperature": 0.4, }, timeout=60,)reply.raise_for_status()body = reply.json()print(body["choices"][0]["message"]["content"])print(body["usage"])
Response
A successful call returns a chat.completion object: the answer is in choices[0].message.content, choices[0].finish_reason says why it ended (stop for a natural end, length when max_tokens cut it off), and usage holds prompt_tokens, completion_tokens, total_tokens and credits_used, the credit charged for this call. Every response, errors included, carries an x-request-id header; send it if you write to support.
Request size
The request body is at most 40 MB; larger gets 413 with request_too_large. Input plus requested output that does not fit the model's context gets 422 with context_length_exceeded.
See the endpoint reference for every parameter and response.
Did this page not help? Tell us.