---
title: "Get LLM completions as a non-streaming response"
method: POST
path: "/.api/completions/code"
---

# Get LLM completions as a non-streaming response

`POST /.api/completions/code`

## Query parameters

- `api-version` 1 | 2 | 3
- `client-name` string
- `client-version` string

## Request body

- CompletionRequest
  - `model` string, required — The language model to use for the completion. Call `/.api/modelconfig/supported-models.json` to get the list of available models.
  - `messages` CompletionMessage[], required — The messages to generate completions for. When using `/.api/completions/code`, only include one message with the speaker 'human'.
    - `role` 'user' | 'assistant' | 'system', required
    - `content` union, required
      - string
      - MessageContentPart[]
        - `type` string, required
  - `maxTokensToSample` integer — The maximum number of tokens to generate before stopping. Note that our models may stop before reaching this maximum. This parameter only specifies the absolute maximum number of tokens to generate.
  - `temperature` number, double — Amount of randomness injected into the response. Defaults to 1.0. Ranges from 0.0 to 1.0. Use temperature closer to 0.0 for analytical / multiple choice, and closer to 1.0 for creative and generative tasks. Note that even with temperature of 0.0, the results will not be fully deterministic.
  - `stopSequences` string[] — Sequences that will cause the model to stop generating. Our models stop on "\n\nHuman:", and may include additional built-in stop sequences in the future. By providing the `stop_sequences` parameter, you may include additional strings that will cause the model to stop generating.
  - `topK` integer — Only sample from the top K options for each subsequent token. Used to remove "long tail" low probability responses. Learn more technical details here: https://towardsdatascience.com/how-to-sample-from-language-models-682bceb97277 Recommended for advanced use cases only. You usually only need to use temperature.
  - `topP` number, double — Use nucleus sampling. In nucleus sampling, we compute the cumulative distribution over all the options for each subsequent token in decreasing probability order and cut it off once it reaches a particular probability specified by `top_p`. You should either alter temperature or `top_p`, but not both. Recommended for advanced use cases only. You usually only need to use temperature.
  - `stream` boolean, nullable — Whether to stream the response. - When true, the response body is an SSE stream of `event: completion\ndata: JSON` where each JSON blob is a `CompletionResponse`. - When false, the response body is a single JSON-encoded `CompletionResponse`.
  - `logprobs` integer — Include the log probabilities on the logprobs most likely tokens, as well the chosen tokens. For example, if logprobs is 5, the API will return a list of the 5 most likely tokens. The API will always return the logprob of the sampled token, so there may be up to logprobs+1 elements in the response. The maximum value for logprobs is 5. For more details, see Fireworks API docs https://docs.fireworks.ai/api-reference/post-completions

## Response `200`

The request has succeeded.

- union
  - CompletionResponse
    - `completion` string — Completion is the full completion string. This field is only present when using the `/.api/completions/code` or when using `api-version=1` or older with `/.api/completions/stream`. In the V2 API for streaming responses, the `deltaText` property is used instead.
    - `deltaText` string — DeltaText is the incremental text that was added to the prompt. This field is only present in streaming responses to `/.api/completions/stream`.
    - `stopReason` string — The reason the model stopped generating tokens. The exact format of this field is defined by the model provider. For OpenAI models, the following stop reasons are defined: - `stop`: the model hit a natural stop point or a provided stop sequence. - `length`: the maximum number of tokens specified in the request was reached. - `content_filter`: content was omitted due content filters. For Anthropic models, the following stop reasons are defined: - "stop_sequence": we reached a stop sequence either provided via the stop_sequences parameter, or a stop sequence built into the model. - "max_tokens": we exceeded max_tokens_to_sample or the model's maximum limit.
    - `logprobs` Logprobs
      - `tokens` string[], required
      - `token_logprobs` number[], required
      - `top_logprobs` object[], required
      - `text_offset` integer[], required
  - CompletionResponse
    - `completion` string — Completion is the full completion string. This field is only present when using the `/.api/completions/code` or when using `api-version=1` or older with `/.api/completions/stream`. In the V2 API for streaming responses, the `deltaText` property is used instead.
    - `deltaText` string — DeltaText is the incremental text that was added to the prompt. This field is only present in streaming responses to `/.api/completions/stream`.
    - `stopReason` string — The reason the model stopped generating tokens. The exact format of this field is defined by the model provider. For OpenAI models, the following stop reasons are defined: - `stop`: the model hit a natural stop point or a provided stop sequence. - `length`: the maximum number of tokens specified in the request was reached. - `content_filter`: content was omitted due content filters. For Anthropic models, the following stop reasons are defined: - "stop_sequence": we reached a stop sequence either provided via the stop_sequences parameter, or a stop sequence built into the model. - "max_tokens": we exceeded max_tokens_to_sample or the model's maximum limit.
    - `logprobs` Logprobs
      - `tokens` string[], required
      - `token_logprobs` number[], required
      - `top_logprobs` object[], required
      - `text_offset` integer[], required

## Changes

- **2024-09-30** `620e12160c8f` — 6 breaking, 2 warning, 3 info
  - added the new required request property `messages/items/content`
  - added the new required request property `messages/items/role`
  - the `anyOf[#/components/schemas/CompletionResponse]/logprobs/allOf[#/components/schemas/Logprobs]/token_logprobs/items/` response's property type/format changed from `number`/`float` to `number`/`double` for status `200`
  - the `anyOf[#/components/schemas/CompletionResponse]/logprobs/allOf[#/components/schemas/Logprobs]/token_logprobs/items/` response's property type/format changed from `number`/`float` to `number`/`double` for status `200`
  - …7 more
- **2024-09-12** `a9bf97d0be4b` — 1 breaking, 5 warning, 2 info
  - the response's body type/format changed from `object`/`` to ``/`` for status `200`
  - removed the request property `prompt`
  - removed the optional property `completion` from the response with the `200` status
  - removed the optional property `deltaText` from the response with the `200` status
  - …4 more
- **2024-09-12** `3721b36fbe3e` — 1 info
  - endpoint added

[Change history](https://skmtc.dev/sourcegraph/apis/sourcegraph-internal-api/changes/.api/completions/code/post.md)

---

[API](https://skmtc.dev/sourcegraph/apis/sourcegraph-internal-api.md) · [All operations](https://skmtc.dev/sourcegraph/apis/sourcegraph-internal-api/llms.txt) · [OpenAPI document](https://skmtc-service-production.skmtc.workers.dev/v1/apis/sourcegraph/sourcegraph-internal-api/revisions/620e12160c8f/schema)
