messages
object[]
required

A list of messages comprising the conversation so far.

model
string
required

Available options: llama3.1-8b, llama3.1-70b

max_tokens
integer | null

The maximum number of tokens that can be generated in the completion. The total length of input tokens and generated tokens is limited by the model’s context length.

response_format
object | null

Setting to { "type": "json_object" } enables JSON mode, which ensures that the response is either a valid JSON object or an error response.

Note that enabling JSON mode does not guarantee that the model will successfully generate valid JSON. The model may fail to generate valid JSON due to various reasons such as incorrect formatting, missing or mismatched brackets, or exceeding the length limit.

In cases where the model fails to generate valid JSON, the error response will be a valid JSON object with a key failed_generation containing the string representing the invalid JSON. This allows you to re-submit the request with additional prompting to correct the issue. The error response will have a 400 server error status code.

Note that JSON mode is not compatible with streaming. "stream" must be set to false.

Important: When using JSON mode, you need to explicitly instruct the model to generate JSON through a system or user message.

seed
integer | null

If specified, our system will make a best effort to sample deterministically, such that repeated requests with the same seed and parameters should return the same result. Determinism is not guaranteed.

stop
string | null

Up to 4 sequences where the API will stop generating further tokens. The returned text will not contain the stop sequence.

stream
boolean | null

If set, partial message deltas will be sent.

temperature
number | null

What sampling temperature to use, between 0 and 1.5. Higher values like 0.8 will make the output more random, while lower values like 0.2 will make it more focused and deterministic. We generally recommend altering this or top_p but not both.

top_p
number | null

An alternative to sampling with temperature, called nucleus sampling, where the model considers the results of the tokens with top_p probability mass. So, 0.1 means only the tokens comprising the top 10% probability mass are considered. We generally recommend altering this or temperature but not both.

tool_choice
string | object

Controls which (if any) tool is called by the model. none means the model will not call any tool and instead generates a message. auto means the model can pick between generating a message or calling one or more tools. required means the model must call one or more tools. Specifying a particular tool via {"type": "function", "function": {"name": "my_function"}} forces the model to call that tool.

none is the default when no tools are present. auto is the default if tools are present.

tools
object | null

A list of tools the model may call. Currently, only functions are supported as a tool. Use this to provide a list of functions the model may generate JSON inputs for.

Specifying tools consumes prompt tokens in the context. If too many are given, the model may perform poorly or you may hit context length limitations

user
string | null

A unique identifier representing your end-user, which can help to monitor and detect abuse.

Was this page helpful?