POST
/
chat
/
completions
curl --request POST \
  --url https://api.fireworks.ai/inference/v1/chat/completions \
  --header 'Authorization: Bearer <token>' \
  --header 'Content-Type: application/json' \
  --data '{
  "model": "accounts/fireworks/models/llama-v2-7b-chat",
  "messages": [
    {
      "role": "system",
      "content": "<string>",
      "name": "<string>"
    }
  ],
  "tools": [
    {
      "type": "function",
      "function": {
        "description": "<string>",
        "name": "<string>",
        "parameters": {
          "type": "object",
          "required": [
            "<string>"
          ],
          "properties": {}
        }
      }
    }
  ],
  "max_tokens": 123,
  "prompt_truncate_len": 123,
  "temperature": 1,
  "top_p": 1,
  "top_k": 50,
  "frequency_penalty": 0,
  "presence_penalty": 0,
  "n": 1,
  "stop": "<string>",
  "response_format": {
    "type": "json_object",
    "schema": {}
  },
  "stream": true,
  "context_length_exceeded_behavior": "truncate",
  "user": "<string>"
}'
{
  "id": "<string>",
  "object": "<string>",
  "created": 123,
  "model": "<string>",
  "choices": [
    {
      "index": 123,
      "message": {
        "role": "system",
        "content": "<string>",
        "tool_calls": [
          {
            "id": "<string>",
            "type": "function",
            "function": {
              "name": "<string>",
              "arguments": "<string>"
            }
          }
        ]
      },
      "finish_reason": "stop"
    }
  ],
  "usage": {
    "prompt_tokens": 123,
    "completion_tokens": 123,
    "total_tokens": 123
  }
}

Authorizations

Authorization
string
headerrequired

Bearer authentication header of the form Bearer <token>, where <token> is your auth token.

Body

application/json
model
string
required

The name of the model to use.

messages
object[]
required

A list of messages comprising the conversation so far.

tools
object[]

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. See the guide for more information and the list of supported models: https://docs.fireworks.ai/docs/function-calling#supported-models

max_tokens
integer
default: 200

The maximum number of tokens to generate in the completion.

If the token count of your prompt (previous messages) plus max_tokens exceed the model's context length, the behavior is depends on context_length_exceeded_behavior. By default, max_tokens will be lowered to fit in the context window instead of returning an error.

prompt_truncate_len
integer | null
default: 1500

The size to which to truncate chat prompts. Earlier user/assistant messages will be evicted to fit the prompt into this length.

This should usually be set to a number << the max context size of the model, to allow enough remaining tokens for generating a response.

If omitted, you may receive "prompt too long" errors in your responses as conversations grow. Note that even with this set, you may still receive "prompt too long" errors if individual messages are too long for the model context window.

temperature
number | null
default: 1

What sampling temperature to use, between 0 and 2. 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
default: 1

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.

top_k
integer | null

Top-k sampling is another sampling method where the k most probable next tokens are filtered and the probability mass is redistributed among only those k next tokens. The value of k controls the number of candidates for the next token at each step during text generation.

frequency_penalty
number | null
default: 0

Number between -2.0 and 2.0. Positive values penalize new tokens based on their existing frequency in the text so far, decreasing the model's likelihood to repeat the same line verbatim.

Reasonable value is around 0.1 to 1 if the aim is to just reduce repetitive samples somewhat. If the aim is to strongly suppress repetition, then one can increase the coefficients up to 2, but this can noticeably degrade the quality of samples. Negative values can be used to increase the likelihood of repetition.

See also presence_penalty for penalizing tokens that have at least one appearance at a fixed rate.

presence_penalty
number | null
default: 0

Number between -2.0 and 2.0. Positive values penalize new tokens based on whether they appear in the text so far, increasing the model's likelihood to talk about new topics.

Reasonable value is around 0.1 to 1 if the aim is to just reduce repetitive samples somewhat. If the aim is to strongly suppress repetition, then one can increase the coefficients up to 2, but this can noticeably degrade the quality of samples. Negative values can be used to increase the likelihood of repetition.

See also frequence_penalty for penalizing tokens at an increasing rate depending on how often they appear.

n
integer | null
default: 1

How many completions to generate for each prompt.

Note: Because this parameter generates many completions, it can quickly consume your token quota. Use carefully and ensure that you have reasonable settings for max_tokens and stop.

stop

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

response_format
object | null

Allows to force the model to produce specific output format.

Setting to { "type": "json_object" } enables JSON mode, which guarantees the message the model generates is valid JSON.

Optional JSON schema can be provided as response_format = {"type": "json_object", "schema": <json_schema>}.

Important: when using JSON mode, it's crucial to also instruct the model to produce JSON via a system or user message. Without this, the model may generate an unending stream of whitespace until the generation reaches the token limit, resulting in a long-running and seemingly "stuck" request. Also note that the message content may be partially cut off if finish_reason="length", which indicates the generation exceeded max_tokens or the conversation exceeded the max context length. In this case the return value might not be a valid JSON.

stream
boolean | null
default: false

Whether to stream back partial progress. If set, tokens will be sent as data-only server-sent events as they become available, with the stream terminated by a data: [DONE] message.

context_length_exceeded_behavior
enum<string>

What to do if the token count of prompt plus max_tokens exceeds the model's context window.

Passing truncate limits the max_tokens to at most context_window_length - prompt_length. This is the default.

Passing error would trigger a request error.

The default of 'truncate' is selected as it allows to ask for high max_tokens value while respecting the context window length without having to do client-side prompt tokenization.

Note, that it differs from OpenAI's behavior that matches that of error.

Available options:
truncate,
error
user
string | null

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

Response

200 - application/json
id
string
required

A unique identifier of the response.

object
string
required

The object type, which is always "chat.completion".

created
integer
required

The Unix time in seconds when the response was generated.

model
string
required

The model used for the chat completion.

choices
object[]
required

The list of chat completion choices.

usage
object

Usage statistics.

For streaming responses, usage field is included in the very last response chunk returned.

Note that returning usage for streaming requests is an OpenAI API extension. If you use OpenAI SDK, you might access the field directly even if it's not present in the type signature in the SDK.