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

# Generate completion

> ### Description

Interact with the LLM model using the specified model_deployment_id. The LLM model will generate a text completion based on the provided prompt.

```json
{
    "prompt": "What is the capital of France?"
}
```



## OpenAPI

````yaml https://app.stainlessapi.com/api/spec/documented/sgp/openapi.yml post /v4/models/{model_deployment_id}/completions
openapi: 3.1.0
info:
  title: EGP API V4
  description: >-
    This is the parent API for all EGP APIs. If you are looking for the EGP API,
    please go to https://api.egp.scale.com/docs.
  contact:
    name: Scale Generative AI Platform
    url: https://scale.com/genai-platform
  version: 0.1.0
servers:
  - url: https://api.egp.scale.com
security: []
tags:
  - name: Models
    description: Model API.
paths:
  /v4/models/{model_deployment_id}/completions:
    post:
      tags:
        - Models
      summary: Generate completion
      description: >-
        ### Description


        Interact with the LLM model using the specified model_deployment_id. The
        LLM model will generate a text completion based on the provided prompt.


        ```json

        {
            "prompt": "What is the capital of France?"
        }

        ```
      operationId: POST-V4-/models/{model_deployment_id}/completions
      parameters:
        - name: model_deployment_id
          in: path
          required: true
          schema:
            title: Model Deployment Id
            type: string
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/CompletionRequestV2'
      responses:
        '200':
          description: Successful Response
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/CompletionResponse'
        '422':
          description: Validation Error
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/HTTPValidationError'
      x-codeSamples:
        - lang: Python
          source: |-
            import os
            from scale_gp import SGPClient

            client = SGPClient(
                api_key=os.environ.get("SGP_API_KEY"),  # This is the default and can be omitted
            )
            for completion in client.models.completions.create(
                model_deployment_id="model_deployment_id",
                prompt="prompt",
            ):
              print(completion)
        - lang: Go
          source: "package main\n\nimport (\n\t\"context\"\n\t\"fmt\"\n\n\t\"github.com/stainless-sdks/sgp-go\"\n\t\"github.com/stainless-sdks/sgp-go/option\"\n)\n\nfunc main() {\n\tclient := sgp.NewClient(\n\t\toption.WithAPIKey(\"My API Key\"),\n\t)\n\tcompletionResponse, err := client.Models.Completions.New(\n\t\tcontext.TODO(),\n\t\t\"model_deployment_id\",\n\t\tsgp.ModelCompletionNewParams{\n\t\t\tPrompt: sgp.F(\"prompt\"),\n\t\t},\n\t)\n\tif err != nil {\n\t\tpanic(err.Error())\n\t}\n\tfmt.Printf(\"%+v\\n\", completionResponse.Completions)\n}\n"
components:
  schemas:
    CompletionRequestV2:
      properties:
        model_request_parameters:
          $ref: '#/components/schemas/ParameterBindings'
        temperature:
          title: Temperature
          description: >-
            What sampling temperature to use, between [0, 2]. Higher values like
            1.8 will make the output more random, while lower values like 0.2
            will make it more focused and deterministic. Setting temperature=0.0
            will enable fully deterministic (greedy) sampling.NOTE: The
            temperature parameter range for some model is limited to [0, 1] if
            the given value is above the available range, it defaults to the max
            value. Temperature is ignored for OpenAI reasoning models.
          default: 0.2
          type: number
          maximum: 2
          minimum: 0
        stop_sequences:
          title: Stop Sequences
          description: >-
            List of up to 4 sequences where the API will stop generating further
            tokens. The returned text will not contain the stop sequence.
          items:
            type: string
          type: array
          maxItems: 4
        max_tokens:
          title: Max Tokens
          description: >
            The maximum number of tokens to generate in the completion. The
            token count of your prompt plus max_tokens cannot exceed the model's
            context length. If not, specified, max_tokens will be determined
            based on the model used: 

            | Model API family | Model API default | EGP applied default |

            | --- | --- | --- |

            | OpenAI Completions |
            [`16`](https://platform.openai.com/docs/api-reference/completions/create#max_tokens)
            | `context window - prompt size` |

            | OpenAI Chat Completions | [`context window - prompt
            size`](https://platform.openai.com/docs/api-reference/chat/create#max_tokens)
            | `context window - prompt size` |

            | LLM Engine |
            [`max_new_tokens`](https://github.com/scaleapi/launch-python-client/blob/207adced1c88c1c2907266fa9dd1f1ff3ec0ea5b/launch/client.py#L2910)
            parameter is required | `100` |

            | Anthropic Claude 2 |
            [`max_tokens_to_sample`](https://docs.anthropic.com/claude/reference/complete_post)
            parameter is required | `10000` |
          type: integer
        top_p:
          title: Top P
          description: >-
            The cumulative probability cutoff for token selection. Lower values
            mean sampling from a smaller, more top-weighted nucleus. Available
            for models provided by Google, LLM Engine, and OpenAI.
          type: number
        top_k:
          title: Top K
          description: >-
            Sample from the k most likely next tokens at each step. Lower k
            focuses on higher probability tokens. Available for models provided
            by Google and LLM Engine.
          type: number
        frequency_penalty:
          title: Frequency Penalty
          description: >-
            Penalize tokens based on how much they have already appeared in the
            text. Positive values encourage the model to generate new tokens and
            negative values encourage the model to repeat tokens. Available for
            models provided by LLM Engine and OpenAI.
          type: number
        presence_penalty:
          title: Presence Penalty
          description: >-
            Penalize tokens based on if they have already appeared in the text.
            Positive values encourage the model to generate new tokens and
            negative values encourage the model to repeat tokens. Available for
            models provided by LLM Engine and OpenAI.
          type: number
        stream:
          title: Stream
          description: Flag indicating whether to stream the completion response
          default: false
          type: boolean
        logprobs:
          title: Logprobs
          description: >-
            Whether to return logprobs. Currently only supported for llmengine
            chat models.
          type: boolean
        top_logprobs:
          title: Top Logprobs
          description: >-
            Number of top logprobs to return. Currently only supported for
            llmengine chat models.
          type: integer
        chat_template:
          title: Chat Template
          description: >-
            The chat template to use for the completion. Currently only
            supported for llmengine chat models.
          type: string
        chat_template_kwargs:
          title: Chat Template Kwargs
          description: >-
            Additional keyword arguments for the chat template. Currently only
            supported for llmengine chat models.
          additionalProperties: true
          type: object
        reasoning_effort:
          title: Reasoning Effort
          description: >-
            The reasoning effort to use for the completion. Currently only
            supported for openai models.
          type: string
          enum:
            - low
            - medium
            - high
        prompt:
          type: string
          title: Prompt
      additionalProperties: false
      type: object
      required:
        - prompt
      title: CompletionRequestV2
    CompletionResponse:
      properties:
        finish_reason:
          title: Finish Reason
          type: string
        prompt_tokens:
          title: Prompt Tokens
          default: 0
          type: integer
        response_tokens:
          title: Response Tokens
          default: 0
          type: integer
        completions:
          items:
            prefixItems:
              - type: string
              - items:
                  type: string
                type: array
            type: array
            maxItems: 2
            minItems: 2
          type: array
          title: Completions
        choices:
          title: Choices
          items:
            $ref: >-
              #/components/schemas/egp_api_backend__server__utils__model_schemas__completions__Choice
          type: array
      additionalProperties: false
      type: object
      required:
        - completions
      title: CompletionResponse
    HTTPValidationError:
      properties:
        detail:
          items:
            $ref: '#/components/schemas/ValidationError'
          type: array
          title: Detail
      type: object
      title: HTTPValidationError
    ParameterBindings:
      properties:
        bindings:
          additionalProperties:
            anyOf:
              - type: string
              - type: integer
              - type: number
              - type: boolean
          type: object
          title: Bindings
      additionalProperties: false
      type: object
      required:
        - bindings
      title: ParameterBindings
    egp_api_backend__server__utils__model_schemas__completions__Choice:
      properties:
        index:
          type: integer
          title: Index
        logprobs:
          $ref: >-
            #/components/schemas/egp_api_backend__server__utils__model_schemas__completions__ChoiceLogprobs
      type: object
      required:
        - index
      title: Choice
    ValidationError:
      properties:
        loc:
          items:
            anyOf:
              - type: string
              - type: integer
          type: array
          title: Location
        msg:
          type: string
          title: Message
        type:
          type: string
          title: Error Type
        input:
          title: Input
        ctx:
          type: object
          title: Context
          additionalProperties: true
      type: object
      required:
        - loc
        - msg
        - type
      title: ValidationError
    egp_api_backend__server__utils__model_schemas__completions__ChoiceLogprobs:
      properties:
        content:
          title: Content
          items:
            $ref: >-
              #/components/schemas/egp_api_backend__server__utils__model_schemas__completions__ChatCompletionTokenLogprob
          type: array
      type: object
      title: ChoiceLogprobs
    egp_api_backend__server__utils__model_schemas__completions__ChatCompletionTokenLogprob:
      properties:
        token:
          type: string
          title: Token
        bytes:
          title: Bytes
          items:
            type: integer
          type: array
        logprob:
          type: number
          title: Logprob
        top_logprobs:
          items:
            $ref: >-
              #/components/schemas/egp_api_backend__server__utils__model_schemas__completions__TopLogprob
          type: array
          title: Top Logprobs
      type: object
      required:
        - token
        - logprob
        - top_logprobs
      title: ChatCompletionTokenLogprob
    egp_api_backend__server__utils__model_schemas__completions__TopLogprob:
      properties:
        token:
          type: string
          title: Token
        bytes:
          title: Bytes
          items:
            type: integer
          type: array
        logprob:
          type: number
          title: Logprob
      type: object
      required:
        - token
        - logprob
      title: TopLogprob

````