---
title: "Encrypted Chat Completions (RVENC)"
method: POST
path: "/rvenc/chat/completions"
tags: ["Chats", "dev-api"]
---

# Encrypted Chat Completions (RVENC)

`POST /rvenc/chat/completions`

## Request

- Base URL: `https://gateway.prem.io`
- URL: `https://gateway.prem.io/rvenc/chat/completions`
- Auth: HTTP bearer and API key in header `Authorization`

Create a chat completion from an end-to-end encrypted payload, decrypted only inside the confidential compute environment. Stateless: no chat history is kept and no files can be attached.

## Headers

- `X-Queue-Timeout` string

## Request body

- CreateRvencChatCompletionRequest: Chat completion request with an end-to-end encrypted payload and the key material needed to decrypt it.
  - `encryptedInference` string, required: Encrypted JSON string containing all chat completion parameters. When decrypted, this string must match the structure shown in the expandable `_decryptedInference` property below (reference only - do not send this property).
  - `_decryptedInference` RvencInferenceParams: Structure of the JSON to encrypt and send as `encryptedInference`.
    - `messages` union[], required: A list of messages comprising the conversation so far. Depending on the model you use, different message types (modalities) are supported, like text, images, and audio.
      - union
        - object: Developer-provided instructions that the model should follow. With o1 models and newer, use developer messages for this purpose instead.
          - `role` 'system', required: The role of the messages author, in this case system
          - `content` union, required: The contents of the system message
            - string: The contents of the system message
            - object[]: An array of content parts with a defined type. For system messages, only type text is supported
              - …
          - `name` string: An optional name for the participant. Provides the model information to differentiate between participants of the same role
        - object: Messages sent by an end user, containing prompts or additional context information
          - `role` 'user', required: The role of the messages author, in this case user
          - `content` union, required: The contents of the user message
            - string: The text contents of the message
            - union[]: An array of content parts with a defined type. Supported options differ based on the model being used to generate the response. Can contain text, image, or audio inputs
              - …
          - `name` string: An optional name for the participant. Provides the model information to differentiate between participants of the same role
        - object: Messages sent by the model in response to user messages
          - `role` 'assistant', required: The role of the messages author, in this case assistant
          - `audio` object: Data about a previous audio response from the model
            - `id` string, required: Unique identifier for a previous audio response from the model
          - `content` union: The contents of the assistant message. Required unless tool_calls or function_call is specified
            - string
            - object[]
              - …
          - `function_call` object: Deprecated and replaced by tool_calls. The name and arguments of a function that should be called, as generated by the model
            - `name` string, required: The name of the function to call
            - `arguments` string, required: The arguments to call the function with, as generated by the model in JSON format
          - `name` string: An optional name for the participant. Provides the model information to differentiate between participants of the same role
          - `refusal` string: The refusal message by the assistant
          - `tool_calls` object[]: The tool calls generated by the model, such as function calls
            - `id` string, required: Unique identifier for the tool call
            - `type` string, required: Type of tool call
            - `function` object, required
              - …
        - object: Tool message
          - `role` 'tool', required: The role of the messages author, in this case tool
          - `content` union, required: The contents of the tool message
            - string: The contents of the tool message
            - object[]: An array of content parts with a defined type. For tool messages, only type text is supported
              - …
          - `tool_call_id` string, required: Tool call that this message is responding to
        - object: Deprecated function message
          - `role` 'function', required: The role of the messages author, in this case function
          - `content` string, required: The contents of the function message
          - `name` string, required: The name of the function to call
    - `model` string, required: The model identifier to use for completion
    - `temperature` number: Sampling temperature between 0 and 2. Higher values make output more random.
    - `top_p` number: Nucleus sampling parameter. Consider tokens with top_p probability mass.
    - `max_tokens` integer, nullable: The maximum number of tokens that can be generated in the chat completion. This value can be used to control costs for text generated via API. This value is deprecated in favor of max_completion_tokens, and is not supported by reasoning models
    - `max_completion_tokens` integer, nullable: An upper bound for the number of tokens that can be generated for a completion, including visible output tokens and reasoning tokens
    - `stream` boolean, nullable: If set to true, the model response data will be streamed to the client as it is generated using server-sent events
    - `tools` union[]: A list of tools the model may call. You can provide either custom tools or function tools
      - union
        - object: A function tool that can be used to generate a response
          - `type` 'function', required: The type of the tool. Currently, only function is supported
          - `function` object, required
            - `name` string, required: The name of the function to be called. Must be a-z, A-Z, 0-9, or contain underscores and dashes, with a maximum length of 64
            - `description` string: A description of what the function does, used by the model to choose when and how to call the function
            - `parameters` object: The parameters the functions accepts, described as a JSON Schema object. Omitting parameters defines a function with an empty parameter list
        - object: A custom tool that processes input using a specified format
          - `type` 'custom', required: The type of the custom tool. Always custom
          - `custom` object, required: Properties of the custom tool
            - `name` string, required: The name of the custom tool, used to identify it in tool calls
            - `description` string: Optional description of the custom tool, used to provide more context
            - `format` object: The input format for the custom tool. Default is unconstrained text
    - `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 forces the model to call that tool
      - 'none' | 'auto' | 'required': 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
      - object: Specifies a tool the model should use. Use to force the model to call a specific function
        - `type` 'function', required: For function calling, the type is always function
        - `function` object, required
          - `name` string, required: The name of the function to call
      - object: Specifies a tool the model should use. Use to force the model to call a specific custom tool
        - `type` 'custom', required: For custom tool calling, the type is always custom
        - `custom` object, required
          - `name` string, required: The name of the custom tool to call
    - `response_format` union: An object specifying the format that the model must output
      - object: Default response format. Used to generate text responses
        - `type` 'text', required: The type of response format being defined. Always text
      - object: JSON Schema response format. Used to generate structured JSON responses
        - `type` 'json_schema', required: The type of response format being defined. Always json_schema
        - `json_schema` object, required: Structured Outputs configuration options, including a JSON Schema
          - `name` string, required: The name of the response format. Must be a-z, A-Z, 0-9, or contain underscores and dashes, with a maximum length of 64
          - `description` string: A description of what the response format is for, used by the model to determine how to respond in the format
          - `schema` object: The schema for the response format, described as a JSON Schema object
          - `strict` boolean: Whether to enable strict schema adherence when generating the output. If set to true, the model will always follow the exact schema defined in the schema field
      - object: JSON object response format. An older method of generating JSON responses. Using json_schema is recommended for models that support it
        - `type` 'json_object', required: The type of response format being defined. Always json_object
    - `audio` object, nullable: Parameters for audio output. Required when audio output is requested with modalities: ["audio"]
      - `format` 'wav' | 'mp3' | 'flac' | 'opus' | 'pcm16', required: Specifies the output audio format
      - `voice` 'alloy' | 'ash' | 'ballad' | 'coral' | 'echo' | 'fable' | 'nova' | 'onyx' | 'sage' | 'shimmer', required: The voice the model uses to respond
    - `frequency_penalty` number, nullable: Number between -2.0 and 2.0. Positive values penalize new tokens based on their existing frequency in the text so far, decreasing the model's likelihood to repeat the same line verbatim
    - `function_call` union: Deprecated in favor of tool_choice. Controls which (if any) function is called by the model
      - 'none' | 'auto': none means the model will not call a function and instead generates a message. auto means the model can pick between generating a message or calling a function
      - object: Specifying a particular function via {"name": "my_function"} forces the model to call that function
        - `name` string, required: The name of the function to call
    - `functions` object[]: Deprecated in favor of tools. A list of functions the model may generate JSON inputs for
      - `name` string, required: The name of the function to be called. Must be a-z, A-Z, 0-9, or contain underscores and dashes, with a maximum length of 64
      - `description` string: A description of what the function does, used by the model to choose when and how to call the function
      - `parameters` object: The parameters the functions accepts, described as a JSON Schema object. Omitting parameters defines a function with an empty parameter list
    - `logit_bias` object: 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
    - `logprobs` boolean, nullable: 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
    - `metadata` object: Set of 16 key-value pairs that can be attached to an object. Keys are strings with a maximum length of 64 characters. Values are strings with a maximum length of 512 characters
    - `modalities` string[]: Output types that you would like the model to generate
    - `n` integer, nullable: How many chat completion choices to generate for each input message. Note that you will be charged based on the number of generated tokens across all of the choices. Keep n as 1 to minimize costs
    - `prediction` object: Configuration for a Predicted Output, which can greatly improve response times when large parts of the model response are known ahead of time
      - `type` 'content', required: The type of the predicted content you want to provide. This type is currently always content
      - `content` union, required: The content that should be matched when generating a model response
        - string: The content used for a Predicted Output. This is often the text of a file you are regenerating with minor changes
        - object[]: An array of content parts with a defined type. Supported options differ based on the model being used to generate the response. Can contain text inputs
          - `text` string, required: The text content
          - `type` 'text', required: The type of the content part
    - `presence_penalty` number, nullable: Number between -2.0 and 2.0. Positive values penalize new tokens based on whether they appear in the text so far, increasing the model's likelihood to talk about new topics
    - `prompt_cache_key` string: Used to cache responses for similar requests, to improve your cache hit rate. Replaces the user field
    - `prompt_cache_retention` string: The retention policy for the prompt cache. Set to 24h to enable extended prompt caching, which keeps cached prefixes active for longer, up to a maximum of 24 hours
    - `reasoning_effort` 'none' | 'minimal' | 'low' | 'medium' | 'high' | 'xhigh' | 'max': Constrains effort on reasoning for reasoning models. The valid values depend on the model family: Qwen models accept xhigh, medium, and low; DeepSeek and Kimi models accept low, high, and max; Z.ai (GLM) models accept max, xhigh, high, medium, low, minimal, and none. The proxy forwards the value to the model unchanged, so the model rejects a value it does not support. Reducing reasoning effort can result in faster responses and fewer tokens used on reasoning in a response
    - `safety_identifier` string: A stable identifier used to help detect users of your application that may be violating the usage policies. The ID should be a string that uniquely identifies each end user
    - `seed` integer, nullable: This feature is in Beta. If specified, our system will make a best effort to sample deterministically, such that repeated requests with the same seed and parameters should return the same result. Determinism is not guaranteed
    - `service_tier` 'auto' | 'default' | 'flex' | 'priority': Specifies the processing type used for serving the request
    - `stop` union: Up to 4 sequences where the API will stop generating further tokens. The returned text will not contain the stop sequence. Not supported by some reasoning models
      - string
      - string[]
    - `store` boolean, nullable: Whether the model provider may store the output of this chat completion request. Supports text and image inputs. Note: image inputs over 8MB are dropped
    - `stream_options` object: Options for streaming response. Only set this when you set stream: true
      - `include_obfuscation` boolean: When true, stream obfuscation will be enabled. Stream obfuscation adds random characters to an obfuscation field on streaming delta events to normalize payload sizes as a mitigation to certain side-channel attacks
      - `include_usage` boolean: If set, an additional chunk will be streamed before the data: [DONE] message. The usage field on this chunk shows the token usage statistics for the entire request
    - `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
    - `verbosity` 'low' | 'medium' | 'high': Constrains the verbosity of the model's response. Lower values will result in more concise responses, while higher values will result in more verbose responses
    - `web_search_options` object: This tool searches the web for relevant results to use in a response
      - `search_context_size` 'low' | 'medium' | 'high': High level guidance for the amount of context window space to use for the search
      - `user_location` object, nullable: Approximate location parameters for the search
        - `approximate` object, required
          - `city` string: Free text input for the city of the user, e.g. San Francisco
          - `country` string: The two-letter ISO country code of the user, e.g. US
          - `region` string: Free text input for the region of the user, e.g. California
          - `timezone` string: The IANA timezone of the user, e.g. America/Los_Angeles
        - `type` 'approximate', required: The type of location approximation. Always approximate
  - `cipherText` string, required: Cipher text for shared secret generation (ECDH key exchange)
  - `nonce` string, required: Nonce used for encrypting the inference payload
  - `model` string, required: Model identifier to use for completion
  - `stream` boolean: If true, returns a server-sent events stream. If false, returns JSON with `encryptedResponse` and `nonce`. May also be set inside `encryptedInference`.

## Response `200`

RVENC chat completion response. Returns JSON when stream is false or omitted (default), or a server-sent events stream when stream is true.

- RvencChatCompletionNonStreaming: Encrypted non-streaming RVENC chat completion response. Contains the encrypted completion result that must be decrypted using the shared secret derived from the request's cipherText.
  - `encryptedResponse` string, required: Encrypted JSON string containing the chat completion result. Decrypt using XChaCha20-Poly1305 with the shared secret (derived from cipherText) and the response nonce.
  - `nonce` string, required: Hex-encoded nonce used for decrypting the encryptedResponse payload.
  - `usage` object: Token usage statistics for the completion request.
    - `model` string
    - `prompt_tokens` integer
    - `completion_tokens` integer
    - `reasoning_tokens` integer
    - `total_tokens` integer

## Other responses

- `400`: Bad request
- `401`: Access token is missing or invalid
- `403`: You do not have the required permissions to access this resource
- `429`: Too many requests - concurrent stream limit reached
- `502`: The confidential inference service failed to complete the request. `error` carries the reason reported by the model server whenever it returned one.

## Changes

- **2026-11-13** `d46bc3931b34`: 1 breaking, 9 warning, 4 info
  - the request property `model` became required
  - added the new `405.00` enum value to the `allOf[subschema #1]/status` response property for the response status `401`
  - added the new `405.00` enum value to the `allOf[subschema #1]/status` response property for the response status `403`
  - added the new `405.00` enum value to the `status` response property for the response status `400`
  - …10 more
- **2026-10-16** `d5b1beb33be5`: 1 info
  - endpoint added

[Operation history](https://skmtc.dev/premai-io/apis/prem-studio-api/changes/rvenc/chat/completions/post.md)

---

[API](https://skmtc.dev/premai-io/apis/prem-studio-api.md) - [All operations](https://skmtc.dev/premai-io/apis/prem-studio-api/llms.txt) - [OpenAPI document](https://skmtc.dev/premai-io/apis/prem-studio-api/revisions/d46bc3931b34?raw)
