Generate a completion (OpenAI-compatible, non-streaming) Beta

POST /v1/experimental/replicas/{replicaUUID}/chat/completions

Limited OpenAI Chat Completions API compatibility. Supports basic chat completion with standard message roles and JSON responses. Not supported: OpenAI-style streaming, tool calls, stop sequences, logprobs, and most request parameters.

Creates a chat completion response from a list of messages comprising a conversation.

Path parameters

application/json

Body

  • messages array[object] Required

    A list of messages that make up the conversation context. Only the last message is used for completion.

    Hide messages attributes Show messages attributes object
    • role string Required

      The role of the message author. Can be "assistant", "developer", "system", "tool", or "user".

      Values are assistant, developer, system, tool, or user.

    • content string Required

      The content of the message.

      Minimum length is 1, maximum length is 10000.

    • name string

      An optional name for the participant. Provides the model information to differentiate between participants of the same role.

  • store boolean

    When set to false, historical messages are not used in the context, and the message is not appended to the conversation history.

    Default value is true.

  • source string

    The place where the conversation is happening, which informs where the message should be saved in the chat history if store is true.

    Values are discord, embed, or web. Default value is web.

  • Discord information about the message

    Additional properties are NOT allowed.

    Hide discord_data attributes Show discord_data attributes object

Responses

  • 200 application/json

    Chat completion response in OpenAI compatible format

    Hide response attributes Show response attributes object
    • id string Required

      A unique identifier for the chat completion.

    • created integer Required

      The Unix timestamp (in seconds) of when the chat completion was created.

    • object string Required

      The object type, which is always "chat.completion"

      Value is chat.completion.

    • model string Required

      The model used for the chat completion.

    • choices array[object] Required

      An array of chat completion choices.

      Hide choices attributes Show choices attributes object
      • index integer Required

        The index of the choice in the array.

      • message object Required

        The message generated by the model.

        Hide message attributes Show message attributes object
        • role string Required

          The role of the message author, which is always "assistant" for completions.

          Value is assistant.

        • content string Required

          The content of the message.

        • The tool calls generated by the model, such as function calls.

      • Log probabilities for token generation if requested.

      • finish_reason string Required

        The reason the model stopped generating tokens.

        Values are stop, length, tool_calls, content_filter, or function_call.

    • usage object Required

      Usage statistics for the completion request.

      Hide usage attributes Show usage attributes object
  • 400 application/json

    Bad Request

    Hide response attributes Show response attributes object
    • success boolean Required

      Indicates the status of the request

    • error string Required

      A text representation of the error

    • A unique identifier of the event, useful for reporting

    • request_id string Required

      A unique identifier of the request, useful for reporting

  • 401 application/json

    Unauthorized

    Hide response attributes Show response attributes object
    • success boolean Required

      Indicates the status of the request

    • error string Required

      A text representation of the error

    • A unique identifier of the event, useful for reporting

    • request_id string Required

      A unique identifier of the request, useful for reporting

  • 404 application/json

    Not Found

    Hide response attributes Show response attributes object
    • success boolean Required

      Indicates the status of the request

    • error string Required

      A text representation of the error

    • request_id string Required

      A unique identifier of the request, useful for reporting

  • 415 application/json

    Unsupported Media Type

    Hide response attributes Show response attributes object
    • success boolean Required

      Indicates the status of the request

    • error string Required

      A text representation of the error

    • A unique identifier of the event, useful for reporting

    • request_id string Required

      A unique identifier of the request, useful for reporting

  • 500 application/json

    Internal Server Error

    Hide response attributes Show response attributes object
    • success boolean Required

      Indicates the status of the request

    • error string Required

      A text representation of the error

    • A unique identifier of the event, useful for reporting

    • request_id string Required

      A unique identifier of the request, useful for reporting

    • The inner exception

      Hide inner_exception attributes Show inner_exception attributes object
POST /v1/experimental/replicas/{replicaUUID}/chat/completions
curl \
 --request POST 'https://api.sensay.io/v1/experimental/replicas/03db5651-cb61-4bdf-9ef0-89561f7c9c53/chat/completions' \
 --header "X-ORGANIZATION-SECRET: $API_KEY" \
 --header "X-USER-ID: $API_KEY" \
 --header "Content-Type: application/json" \
 --data '{"messages":[{"role":"system","content":"You are a helpful assistant."},{"role":"user","content":"How did you handle the immense pressure during the Civil War?"}],"store":true,"source":"web","discord_data":{"channel_id":"string","channel_name":"string","author_id":"string","author_name":"string","message_id":"string","created_at":"string","server_id":"string","server_name":"string"}}'
Request examples
{
  "messages": [
    {
      "role": "system",
      "content": "You are a helpful assistant."
    },
    {
      "role": "user",
      "content": "How did you handle the immense pressure during the Civil War?"
    }
  ],
  "store": true,
  "source": "web",
  "discord_data": {
    "channel_id": "string",
    "channel_name": "string",
    "author_id": "string",
    "author_name": "string",
    "message_id": "string",
    "created_at": "string",
    "server_id": "string",
    "server_name": "string"
  }
}
Response examples (200)
{
  "id": "chatcmpl-abc123",
  "created": 1677858242,
  "object": "chat.completion",
  "model": "o1",
  "choices": [
    {
      "index": 0,
      "message": {
        "role": "assistant",
        "content": "During the Civil War, I faced tremendous pressure...",
        "tool_calls": []
      },
      "finish_reason": "stop"
    }
  ],
  "usage": {
    "prompt_tokens": 56,
    "completion_tokens": 31,
    "total_tokens": 87
  }
}
Response examples (400)
{
  "success": true,
  "error": "string",
  "fingerprint": "14fceadd84e74ec499afe9b0f7952d6b",
  "request_id": "xyz1::reg1:reg1::ab3c4-1234567890123-0123456789ab"
}
Response examples (401)
{
  "success": true,
  "error": "string",
  "fingerprint": "14fceadd84e74ec499afe9b0f7952d6b",
  "request_id": "xyz1::reg1:reg1::ab3c4-1234567890123-0123456789ab"
}
Response examples (404)
{
  "success": true,
  "error": "string",
  "request_id": "xyz1::reg1:reg1::ab3c4-1234567890123-0123456789ab"
}
Response examples (415)
{
  "success": true,
  "error": "string",
  "fingerprint": "14fceadd84e74ec499afe9b0f7952d6b",
  "request_id": "xyz1::reg1:reg1::ab3c4-1234567890123-0123456789ab"
}
Response examples (500)
{
  "success": true,
  "error": "string",
  "fingerprint": "14fceadd84e74ec499afe9b0f7952d6b",
  "request_id": "xyz1::reg1:reg1::ab3c4-1234567890123-0123456789ab",
  "inner_exception": {
    "name": "Server overheated",
    "cause": "Request too complicated",
    "stack": "Error: Server overheated due to an unexpected situation\n    at Object.eval (eval at <anonymous>...",
    "message": "The server overheated due to an unexpected situation"
  }
}