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

# Create Completion Request

Generate a model response based on the specified prompt and parameters.

## Request Headers

<ParamField header="Content-Type" type="string" required={true}>
  Enum value: `application/json`
</ParamField>

<ParamField header="Authorization" type="string" required={true}>
  Bearer authentication format: Bearer \{\{API Key}}.
</ParamField>

## Request Body

<ParamField body="model" type="string" required={true}>
  The corresponding model name. For available model names, refer to the model library in [JieKou AI](https://jiekou.ai/#model-library).
</ParamField>

<ParamField body="prompt" type="string" required={true}>
  The prompt used to generate the completion (the prompt can be a string, an array of strings, an array of tokens, or an array of token arrays).
</ParamField>

<ParamField body="max_tokens" type="integer" required={false}>
  The maximum number of tokens that can be generated in the completion.<br />The number of tokens in the prompt plus max\_tokens cannot exceed the model's context length.
</ParamField>

<ParamField body="stream" type="boolean | null">
  Whether to use streaming. Defaults to false. If set, tokens will be sent as data-only server-sent events (SSE), and the stream will be terminated by a data: \[DONE] message.
</ParamField>

<ParamField body="stream_options" type="object">
  Streaming response options. Set only when stream is set to true.

  <Expandable title="properties" defaultOpen={false}>
    <ParamField body="include_usage" type="boolean" required={false}>
      If set, an additional chunk will be streamed before the data: \[DONE] message. The usage field in this chunk shows token usage statistics for the entire request, while the choices field is always an empty array. All other chunks will also include a usage field, but its value will be null.
    </ParamField>
  </Expandable>
</ParamField>

<ParamField body="n" type="integer | null">
  How many completions to generate for each prompt. The default value is 1.<br /><br />Note: Since this parameter generates multiple completions, it may quickly consume your token billing quota. Use it with caution and ensure that reasonable values are set for max\_tokens and stop.<br />Required range: 1 \< x \< 128
</ParamField>

<ParamField body="seed" type="integer | null">
  If specified, our system will make a best effort to perform deterministic sampling, so repeated requests with the same seed and parameters should return the same result.
</ParamField>

<ParamField body="frequency_penalty" type="number | null">
  Defaults to 0. Positive values penalize new tokens based on their frequency in the current text, reducing the model's likelihood of repeating the same content.<br /><br />If the goal is only to reduce repeated samples, reasonable values are around 0.1 to 1. If the goal is to strongly suppress repetition, the coefficient can be increased to 2, but this may noticeably reduce sample quality. Negative values can be used to increase the likelihood of repetition.<br /><br />See also presence\_penalty, which penalizes tokens that have appeared at least once at a fixed rate.<br />Required range: -2 \< x \< 2
</ParamField>

<ParamField body="presence_penalty" type="number | null">
  Defaults to 0. Positive values penalize new tokens based on whether they appear in the current text, increasing the model's likelihood of discussing new topics.<br /><br />If the goal is to slightly reduce repeated samples, reasonable values are around 0.1 to 1. If the goal is to strongly suppress repetition, the coefficient can be increased to 2, but this may significantly reduce sample quality. Negative values can be used to increase the likelihood of repetition.<br /><br />See also frequency\_penalty, which penalizes tokens at an increasing rate based on how frequently they appear.<br />Required range: -2 \< x \< 2
</ParamField>

<ParamField body="repetition_penalty" type="number | null">
  Applies a penalty to repeated tokens to discourage or encourage repetition. A value of 1.0 means no penalty and allows free repetition. Values greater than 1.0 penalize repetition, reducing the likelihood of repeated tokens. Values between 0.0 and 1.0 reward repetition, increasing the chance of repeated tokens. For a good balance, 1.2 is generally recommended. Note that in decoder-only models, the penalty is applied to both the generated output and the prompt.<br />Required range: 0 \< x \< 2
</ParamField>

<ParamField body="stop" type="string | null">
  Up to 4 sequences where the API will stop generating more tokens. The returned text includes the stop sequence.
</ParamField>

<ParamField body="temperature" type="number | null">
  The degree of randomness in the completion. The default value is 1, between 0 and 2. Higher values (such as 0.8) make the output more random, while lower values (such as 0.2) make the output more focused and deterministic.<br /><br />We generally recommend adjusting either this or top\_p, but not both.<br />Required range: 0 \< x \< 2
</ParamField>

<ParamField body="top_p" type="number | null">
  An alternative to temperature, called nucleus sampling, where the model considers the results of tokens with top\_p probability mass. Therefore, 0.1 means only tokens comprising the top 10% probability mass are considered. We generally recommend adjusting either this or temperature, but not both.<br />Required range: 0 \< x ≤ 1
</ParamField>

<ParamField body="top_k" type="integer | null">
  Top-k sampling is another sampling method in which the k most likely next tokens are filtered out, and the probability mass is redistributed only among these k tokens. The value of k controls the number of candidate next tokens when generating text at each step.<br />Required range: 1 \< x \< 128
</ParamField>

<ParamField body="min_p" type="number | null">
  A floating-point value representing the minimum probability for a token to be considered, relative to the probability of the most likely token.<br />Required range: 0 ≤ x ≤ 1
</ParamField>

<ParamField body="logit_bias" type="map[string, integer]">
  Defaults to null. Modifies the likelihood of specified tokens appearing in the completion. Accepts a JSON object that maps tokens to associated bias values from -100 to 100.
</ParamField>

<ParamField body="logprobs" type="integer | null">
  Returns the log probabilities of the logprobs most likely output tokens, along with the probability of the selected token. For example, if logprobs is set to 5, the API will return a list of the log probabilities of the top 5 most likely tokens at each generation step.<br />The maximum value of logprobs is 5.
</ParamField>

<ParamField body="best_of" type="integer">
  Defaults to 1. Generates best\_of completions and processes them server-side, returning the "best" one (that is, the one with the highest log probability per token). Results cannot be streamed.<br /><br />When used with n, best\_of controls the number of candidate completions, and n specifies how many completions to return. best\_of must be greater than n.<br /><br />Note: Since this parameter generates multiple completions, it may quickly consume your token billing quota. Use it with caution and ensure that reasonable values are set for max\_tokens and stop.
</ParamField>

## Response Information

<ResponseField name="choices" type="object[]" required={true}>
  A list of generated completion choices.

  <Expandable title="properties" defaultOpen={true}>
    <ResponseField name="finish_reason" type="string" required={true}>
      The reason the model stopped generating tokens. `stop` if the model reached a natural stopping point or a provided stop sequence; `length` if the maximum number of tokens specified in the request was reached. Enum values: `stop,length`.
    </ResponseField>

    <ResponseField name="index" type="integer" required={true}>
      The index of the completion choice.
    </ResponseField>

    <ResponseField name="logprobs" type="object" required={true}>
      Log probabilities of the most likely tokens.

      <Expandable title="properties" defaultOpen={true}>
        <ResponseField name="text_offset" type="integer[]">
          An integer array of text offsets.
        </ResponseField>

        <ResponseField name="token_logprobs" type="number[]">
          A numeric array of token log probabilities.
        </ResponseField>

        <ResponseField name="tokens" type="string[]">
          A string array of tokens.
        </ResponseField>

        <ResponseField name="top_logprobs" type="object[]">
          An array of objects containing the top log probabilities.

          <Expandable title="properties">
            <ResponseField name="{key}" type="integer" required={true}>
              The log probability value for the given key.
            </ResponseField>
          </Expandable>
        </ResponseField>
      </Expandable>
    </ResponseField>

    <ResponseField name="text" type="string" required={true}>
      The content returned by the completion.
    </ResponseField>
  </Expandable>
</ResponseField>

<ResponseField name="created" type="integer" required={true}>
  The Unix timestamp (in seconds) when the response was generated.
</ResponseField>

<ResponseField name="id" type="string" required={true}>
  The unique identifier of the response.
</ResponseField>

<ResponseField name="model" type="string" required={true}>
  The model used for the completion.
</ResponseField>

<ResponseField name="object" type="string" required={true}>
  The object type, always text\_completion.
</ResponseField>

<ResponseField name="usage" type="object" required={true}>
  Usage statistics.<br />For streaming responses, the usage field is included in the last response chunk returned.

  <Expandable title="properties" defaultOpen={true}>
    <ResponseField name="completion_tokens" type="integer" required={true}>
      The number of tokens generated by the completion.
    </ResponseField>

    <ResponseField name="prompt_tokens" type="integer" required={true}>
      The number of tokens in the prompt.
    </ResponseField>

    <ResponseField name="total_tokens" type="integer" required={true}>
      The total number of tokens used in the request (prompt + completion).
    </ResponseField>
  </Expandable>
</ResponseField>
