Hoveydai

Chat completions

The main endpoint and its parameters.

Reading time: 2 min

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.

ParameterTypeDescription
modelstring, requiredA model id from /v1/models, or auto for the default model.
messageslist, requiredThe conversation so far, oldest first. Each message has a role (system, developer, user or assistant) and content.
max_tokens / max_completion_tokensintegerThe longest answer to produce, in tokens (small pieces of text, roughly a short word or part of a word). Up to 8192.
temperaturenumber, 0 to 2How random the answer is. Lower, such as 0.2, gives more precise and repeatable answers; higher, such as 1, gives more varied ones.
top_pnumber, 0 to 1An 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.
stopstring or listUp to 4 strings; the answer ends before the first one it would produce.
streambooleanSend the answer in chunks as it is written; see Streaming.
stream_options.include_usagebooleanIn a stream, also send usage in the last chunk.
nintegerMust 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.