---
title: "Create Chat Completion"
method: POST
path: "/v1/chat/completions"
tags: ["text"]
---

# Create Chat Completion

`POST /v1/chat/completions`

Create a Chat Completion.

## Request body

- CreateChatCompletionRequest — An OpenAI API compatible chat completion request.
  - `frequency_penalty` number — Penalizes new tokens based on their frequency in the generated text so far.
  - `ignore_eos` boolean — Whether to ignore the EOS token and continue generating tokens after the EOS token is generated.
  - `log_prompt` boolean — OctoAI stores request prompt if True.
  - `logit_bias` object, nullable — Modify the likelihood of specified tokens appearing in the completion. Accepts a JSON object that maps tokens (specified by their token ID in the tokenizer) to an associated bias value from -100 to 100. Mathematically, the bias is added to the logits generated by the model prior to sampling. The exact effect will vary per model, but values between -1 and 1 should decrease or increase likelihood of selection; values like -100 or 100 should result in a ban or exclusive selection of the relevant token. As an example, you can pass {'50256': -100} to prevent the <|endoftext|> token from being generated.
  - `loglikelihood` boolean — Return log probabilities for all prompt tokens excluding the first one from prefill step if True.
  - `logprobs` boolean — Whether to return log probabilities of the output tokens or not. If true, returns the log probabilities of each output token returned in the content of message.
  - `max_tokens` integer — Maximum number of tokens to generate per output sequence.
  - `messages` ChatMessage[], required — A list of messages comprising the conversation so far.
    - `content` union, required — The contents of the message.
      - string
      - union[]
        - union
          - MultiModalImageMessage — Multi modal image message.
            - `image_url` ImageURL, required — Image URL for multi modal messages.
              - …
            - `type` 'image_url' — The type of the content part.
          - MultiModalTextMessage — Multi modal text message.
            - `text` string, required — The text content of an multimodal message.
            - `type` 'text' — The type of the content part.
    - `role` string, required — The role of the author of this message.
    - `tool_calls` ToolCall[], nullable — The tool calls generated by the model, such as function calls.
      - `function` FunctionCall, required — The representation of a function called during tool use.
        - `arguments` string, required — The arguments to the function call.
        - `name` string, required — The name of the function to call.
      - `id` string — A unique ID for the tool call used to reference it in the response.
      - `type` 'function' — The type of tool. Today only `function` is supported.
  - `min_p` number — Sets a dynamic threshold of the top tokens to consider based on the probability value of the most likely next token. Following https://arxiv.org/abs/2407.01082.
  - `model` string, required — The identifier of the model to use. Can be a shared tenancy or custom model identifier.
  - `n` integer — Number of output sequences to return.
  - `peft` string, nullable — Parameter-efficient fine-tuning ID.
  - `presence_penalty` number — Penalizes new tokens based on whether they appear in the generated text so far.
  - `repetition_penalty` number — Controls the likelihood of the model generating repeated texts.
  - `response_format` ChatCompletionResponseFormat — OctoAI chat completion response format.
    - `schema` object, nullable — The schema for the response format.
    - `type` string, required — The type of response format.
  - `stop` union — Generation stop condition.
    - string
    - string[]
  - `stream` boolean — If set, tokens will be streamed incrementally to users. One or more tokens will be sent as server-sent events (SSE) as they become available. For more information on read above.
  - `stream_options` StreamOptions — Streaming options for the request.
    - `include_usage` boolean — Whether or not to include token usage stats on the final chunk before the [Done] message.
  - `temperature` number — Controls the randomness of the sampling.
  - `tool_choice` union — Controls which (if any) tool is called by the model. none means the model will not call any tool and instead generates a message. auto means the model can pick between generating a message or calling one or more tools. required means the model must call one or more tools. Specifying a particular tool via {"type": "function", "function": {"name": "my_function"}} forces the model to call that tool. none is the default when no tools are present. auto is the default if tools are present.
    - 'auto'
    - 'required'
    - FunctionChoice — The choice of function to call.
      - `function` FunctionHandle, required — The name of the function to call.
        - `name` string, required — The name of the function that was called.
      - `type` 'function' — The type of tool. Today only `function` is supported.
  - `tools` ToolDefinition[], nullable — 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. A max of 128 functions are supported.
    - `function` FunctionDefinition, required — A definition of a function to call in tool use.
      - `description` string — A description of what the function does. This can used by the model to choose when and how to call the function.
      - `name` string, required — The name of the function to be defined.
      - `parameters` object — The parameters the function accepts described as a JSON Schema.
    - `type` 'function' — The type of tool. Today only `function` is supported.
  - `top_logprobs` integer — An integer between 0 and 20 specifying the number of most likely tokens to return at each token position, each with an associated log probability. `logprobs` must be set to `true` if this parameter is used.
  - `top_p` number — Controls the cumulative probability of the top tokens to consider.
  - `user` string, nullable — A unique identifier representing your end-user.

## Response `200`

An OctoAI text endpoint can be requested in either a synchronous orstreaming mode.When the request body has `stream: False` set the content type will be`application/json`. When the request body has `stream: True` set thecontent type will be `text-event-stream` and will respond with a stream of[server-send-events (SSE)](https://en.wikipedia.org/wiki/Server-sent_events).

- ChatCompletionResponse — An OpenAI API compatible schema for a chat completion response object.
  - `choices` ChatCompletionChoice[], required — A list of chat completion choices.Can be more than one if n is greater than 1.
    - `finish_reason` 'stop' | 'length' | 'tool_calls' | 'content_filter' | 'function_call' | 'cancelled' — The reason why the model stopped generating tokens. This will be `stop` if the model naturally completed generation or encountered a provided stop sequence, `length` if the maximum number of tokens specified in the request was reached, content_filter if content was omitted due to a flag from our content filters, tool_calls if the model called a tool, or function_call (deprecated) if the model called a function.
    - `index` integer, required — A unique identifier for the completion.
    - `logprobs` Logprobs — An OpenAI API compatible schema for logprobs output. See details in `https://platform.openai.com/docs/api-reference/chat/object#chat-create-logprobs`.
      - `content` LogprobsContent[] — List of logprobs info.
        - `bytes` unknown[], nullable — A list of integers representing the UTF-8 bytes representation of the token. Useful in instances where characters are represented by multiple tokens and their byte representations must be combined to generate the correct text representation. Can be null if there is no bytes representation for the token.
          - unknown
        - `logprob` number, required — Logprob corresponding to the token.
        - `token` string, required — New generated token or token from prompt for loglikelihood case.
        - `top_logprobs` TopLogprobs[] — List of top tokens info.
          - `bytes` unknown[], nullable — A list of integers representing the UTF-8 bytes representation of the token. Useful in instances where characters are represented by multiple tokens and their byte representations must be combined to generate the correct text representation. Can be null if there is no bytes representation for the token.
            - unknown
          - `logprob` number, required — Logprob corresponding to the top token.
          - `token` string, required — Token from the top list.
    - `message` ChatMessage, required — An OpenAI API compatible schema for a single ChatMessage.
      - `content` union, required — The contents of the message.
        - string
        - union[]
          - union
            - MultiModalImageMessage — Multi modal image message.
              - …
            - MultiModalTextMessage — Multi modal text message.
              - …
      - `role` string, required — The role of the author of this message.
      - `tool_calls` ToolCall[], nullable — The tool calls generated by the model, such as function calls.
        - `function` FunctionCall, required — The representation of a function called during tool use.
          - `arguments` string, required — The arguments to the function call.
          - `name` string, required — The name of the function to call.
        - `id` string — A unique ID for the tool call used to reference it in the response.
        - `type` 'function' — The type of tool. Today only `function` is supported.
  - `created` integer, required — The Unix timestamp (in seconds) of when the chat completion was created.
  - `id` string, required — A unique identifier for the chat completion.
  - `model` string, required — The model used for the chat completion.
  - `object` 'chat.completion' — Object type field which is a constant and preset.
  - `usage` UsageStats, required — The token usage statistics for a request.
    - `completion_tokens` integer, required — Number of tokens in the prompt.
    - `prompt_tokens` integer, required — Number of tokens in the prompt.
    - `total_tokens` integer, required — Total number of tokens used in the request (prompt + completion).

## Other responses

- `422` — Validation Error
- `500` — Internal Server Error

---

[API](https://skmtc.net/octoml/apis/ollm-api.md) · [All operations](https://skmtc.net/octoml/apis/ollm-api/llms.txt) · [OpenAPI document](https://skmtc-service-staging.skmtc.workers.dev/v1/apis/octoml/ollm-api/revisions/790b47aba5c5/schema)
