> ## Documentation Index
> Fetch the complete documentation index at: https://docs.blinkops.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Generate Chat Completion

Generate a chat completion from a model using a conversation history.

<Note>
  External Documentation

  To learn more, visit the [LiteLLM documentation](https://docs.litellm.ai/docs/completion).
</Note>

## Basic Parameters

<div className="integrations-table">
  | Parameter                     | Description                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                      |
  | ----------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
  | Completions Number            | The number of completions to generate.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           |
  | Frequency Penalty             | Penalize new tokens based on their existing frequency. Accept values from `-2.0` to `2.0`.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       |
  | Include Log Probabilities     | Select to include the log probabilities for the most likely tokens.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                              |
  | Include Top Log Probabilities | The number of log probabilities to return for the most likely tokens at each generation step. <br /><br />Accepts an integer value between `0` and `5`. This parameter is only available when `logprobs` is set to `true`.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       |
  | Logit Bias                    | A JSON object mapping token IDs to bias values. This modifies the probability of generating specific tokens.<br />        <br />Example:<br /><pre><code>\{<br />  "2683": -100,<br />  "7211": 5<br />}</code></pre>                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                            |
  | Max Completion Tokens         | The maximum number of tokens to generate in the completion. This includes visible output tokens and reasoning tokens.<br /><br />**Note:** This parameter can't be used along with `Max Tokens`.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                 |
  | Max Tokens                    | The maximum number of tokens to generate in the completion.<br /><br />**Note:** This parameter can't be used along with `Max Completion Tokens`.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                |
  | Messages                      | The list of messages in the conversation.<br /><br />Example:<br /><pre><code>\[<br />  \{<br />    "role": "system",<br />    "content": "You are a helpful assistant that answers questions about programming."<br />  },<br />  \{<br />    "role": "user",<br />    "content": "Can you explain what a JSON map is?"<br />  }<br />]</code></pre>                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                            |
  | Model ID                      | The ID of the model to get chat completions with.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                |
  | Parallel Tool Calls           | Select to allow the model to call multiple tools in parallel.<br /><br />**Note:** To set this parameter to `True`, the parameter `Tools` must be set.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           |
  | Presence Penalty              | Penalize tokens based on whether they appear in the text so far. Valid range is `-2.0` - `2.0`.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                  |
  | Provider                      | Select a provider of the chat model, this will allow to have access to the corresponding parameters.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                             |
  | Response Format               | The format that the model must output.<br />    <br />Set to `{ "type": "json_object" }` to enable JSON mode, which guarantees the model generates valid JSON.<br />    <br />**Important Note:** When using JSON mode, you must also instruct the model to produce JSON via a system or user message. Without this, the model may generate whitespace indefinitely until reaching the token limit.                                                                                                                                                                                                                                                                                                                                                                                                                                                                              |
  | Safety Identifier             | A unique ID to help track and manage safety-related requests.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                    |
  | Seed                          | A seed to make the generated output more deterministic.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                          |
  | Stop Tokens                   | A comma-separated list of tokens that will stop the generation.<br /><br />Example: `\n`, `END`, `---`                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           |
  | Temperature                   | The degree of randomness to use in the generation. Valid range is `0.0` - `2.0`.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                 |
  | Tool Choice                   | Control which function is called by the model. This parameter accepts either a string or an object.<br /><br />The optional values for string are:<br />\* `auto`<br />\* `required`<br />\* `none`<br /><br />Object Example:<br /><pre><code>\{<br />    "type": "function",<br />    "function": \{<br />      "name": "get\_weather"<br />    }<br />  }</code></pre>                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                        |
  | Tools                         | A list of JSON objects representing tools that the model can use.<br /><br />Example:<br /><pre><code>\[<br />    \{<br />      "type": "function",<br />      "function": \{<br />        "name": "get\_weather",<br />        "description": "Fetches the current weather for a given location.",<br />        "parameters": \{<br />          "type": "object",<br />          "properties": \{<br />            "location": \{<br />              "type": "string",<br />              "description": "The city or location to get the weather for."<br />            },<br />            "date": \{<br />              "type": "string",<br />              "description": "The date for which to get the weather (YYYY-MM-DD)."<br />            }<br />          },<br />          "required": \["location"]<br />        }<br />      }<br />    }<br />  ]</code></pre> |
  | Top P                         | An alternative to sampling with temperature, called nucleus sampling, where the model considers the results of the tokens with `Top P` probability mass.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                         |
  | User ID                       | The ID of the user to associate with the request.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                |
</div>

## Advanced Parameters

<div className="integrations-table">
  | Parameter             | Description                                                                                                                                                                                                                                                                                                                                                                           |
  | --------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
  | API Base              | The API endpoint you want to call the model with.                                                                                                                                                                                                                                                                                                                                     |
  | API Version           | The API version for the call. This is an Azure specific parameter.                                                                                                                                                                                                                                                                                                                    |
  | Additional Parameters | A JSON object for additional body parameters. Values specified in this parameter will override equivalent parameters.<br /><br />For example:<br /><pre><code>\{<br />    "first\_key": 12345,<br />    "second\_key": "some\_value"<br />}</code></pre>The object must follow the vendor's structure as defined in the [API documentation](https://docs.litellm.ai/docs/completion). |
  | Fallbacks             | A List of JSON objects representing fallback models to use in case the primary model fails.<br /><br />Example:<br /><pre><code>\[<br />    \{<br />      "openai/\*": \[<br />        "gpt-4o-mini"<br />      ]<br />    }<br />  ]</code></pre>                                                                                                                                    |
  | Metadata              | Additional metadata to send with the request for logging.<br /><br />Example:<br /><pre><code>\{<br />    "request\_id": "req-8f21c9a2",<br />    "tenant\_id": "acme-prod",<br />    "workflow": "blink-workflow",<br />    "feature": "docs-helper",<br />    "trace\_id": "trace-91b7e3",<br />    "user\_id": "user-1234",<br />    "debug": true<br />  }</code></pre>           |
  | Num Retries           | The number of times to retry the request in case of `APIError`, `TimeoutError` or `ServiceUnavailableError`.                                                                                                                                                                                                                                                                          |
</div>

## Example Output

```json theme={"dark"}
{
	"id": "chatcmpl-CzHVeyzZj09MzGSXlmesrcTztrr66",
	"created": 1768721350,
	"model": "gpt-4o-mini-2024-07-18",
	"object": "chat.completion",
	"system_fingerprint": "fp_29330a9688",
	"choices": [
		{
			"finish_reason": "stop",
			"index": 0,
			"message": {
				"content": "The current weather in New York City is cloudy, with a temperature of 12°C.",
				"role": "assistant"
			},
			"logprobs": {
				"content": [
					{
						"token": "The",
						"bytes": [
							84
						],
						"logprob": -0.001632451661862433,
						"top_logprobs": [
							{
								"token": "The",
								"bytes": [
									84
								],
								"logprob": -0.001632451661862433
							},
							{
								"token": "In",
								"bytes": [
									73
								],
								"logprob": -7.001632213592529
							},
							{
								"token": "Currently",
								"bytes": [
									67
								],
								"logprob": -7.376632213592529
							}
						]
					}
				]
			}
		}
	]
}
```

## Workflow Library Example

[Generate Chat Completion with Litellm and Send Results Via Email](https://library.blinkops.com/workflows/generate-chat-completion-with-litellm-and-send-results-via-email)

<div className="iframe-wrapper">
  <div className="iframe-media">
    <img src="https://mintcdn.com/blinkops-2/ojHYuDeYX5FWuN8a/img/Icons/play-box.svg?fit=max&auto=format&n=ojHYuDeYX5FWuN8a&q=85&s=b8af968e71438a9499c3223c9bd29fb2" alt="Workflow Library" width="16" height="16" data-path="img/Icons/play-box.svg" />

    Preview this Workflow on desktop
  </div>

  <iframe className="iframe" src="https://library.blinkops.com/workflows/generate-chat-completion-with-litellm-and-send-results-via-email/canvas" />
</div>
