Morpheus API Gateway LogoMorpheus API Gateway
Chat

Create Chat Completion

Create a chat completion with automatic session creation if enabled.

POST
/api/v1/chat/completions

Authorization

AuthorizationRequiredBearer <token>

🚀 OAuth2 authentication via secure identity provider

In: header

Scope: openid, email, profile

AuthorizationRequiredBearer <token>

🎫 JWT Bearer token from OAuth2 login or direct token

In: header

Authorization<token>

🗝️ API key in format: 'Bearer sk-xxxxxx'

In: header

Request Body

application/jsonRequired
modelstring | null | null
messagesRequiredMessages
temperaturenumber | null | null
top_pnumber | null | null
ninteger | null | null
streamboolean | null | null
stopstring | array<unknown> | null | null
max_tokensinteger | null | null
presence_penaltynumber | null | null
frequency_penaltynumber | null | null
toolsarray<unknown> | null | null
tool_choicestring | object | null | null
session_idstring | null | null

Response Body

Successful Response

TypeScript Definitions

Use the response body type in TypeScript.

responseRequiredunknown

Validation Error

TypeScript Definitions

Use the response body type in TypeScript.

detailDetail

@minItems 0

curl -X POST "https://example.com/api/v1/chat/completions" \
  -H "Authorization: Bearer <token>" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "string",
    "messages": [
      {
        "role": "string",
        "content": "string",
        "name": "string",
        "tool_calls": [
          {}
        ],
        "tool_call_id": "string"
      }
    ],
    "temperature": 1,
    "top_p": 1,
    "n": 1,
    "stream": false,
    "stop": "string",
    "max_tokens": 0,
    "presence_penalty": 0,
    "frequency_penalty": 0,
    "tools": [
      {
        "type": "function",
        "function": {
          "name": "string",
          "description": "string",
          "parameters": {}
        }
      }
    ],
    "tool_choice": "string",
    "session_id": "string"
  }'
const body = JSON.stringify({
  "model": "string",
  "messages": [
    {
      "role": "string",
      "content": "string",
      "name": "string",
      "tool_calls": [
        {}
      ],
      "tool_call_id": "string"
    }
  ],
  "temperature": 1,
  "top_p": 1,
  "n": 1,
  "stream": false,
  "stop": "string",
  "max_tokens": 0,
  "presence_penalty": 0,
  "frequency_penalty": 0,
  "tools": [
    {
      "type": "function",
      "function": {
        "name": "string",
        "description": "string",
        "parameters": {}
      }
    }
  ],
  "tool_choice": "string",
  "session_id": "string"
})

fetch("https://example.com/api/v1/chat/completions", {
  headers: {
    "Authorization": "Bearer <token>"
  },
  body
})
package main

import (
  "fmt"
  "net/http"
  "io/ioutil"
  "strings"
)

func main() {
  url := "https://example.com/api/v1/chat/completions"
  body := strings.NewReader(`{
    "model": "string",
    "messages": [
      {
        "role": "string",
        "content": "string",
        "name": "string",
        "tool_calls": [
          {}
        ],
        "tool_call_id": "string"
      }
    ],
    "temperature": 1,
    "top_p": 1,
    "n": 1,
    "stream": false,
    "stop": "string",
    "max_tokens": 0,
    "presence_penalty": 0,
    "frequency_penalty": 0,
    "tools": [
      {
        "type": "function",
        "function": {
          "name": "string",
          "description": "string",
          "parameters": {}
        }
      }
    ],
    "tool_choice": "string",
    "session_id": "string"
  }`)
  req, _ := http.NewRequest("POST", url, body)
  req.Header.Add("Authorization", "Bearer <token>")
  req.Header.Add("Content-Type", "application/json")
  res, _ := http.DefaultClient.Do(req)
  defer res.Body.Close()
  body, _ := ioutil.ReadAll(res.Body)

  fmt.Println(res)
  fmt.Println(string(body))
}
import requests

url = "https://example.com/api/v1/chat/completions"
body = {
  "model": "string",
  "messages": [
    {
      "role": "string",
      "content": "string",
      "name": "string",
      "tool_calls": [
        {}
      ],
      "tool_call_id": "string"
    }
  ],
  "temperature": 1,
  "top_p": 1,
  "n": 1,
  "stream": false,
  "stop": "string",
  "max_tokens": 0,
  "presence_penalty": 0,
  "frequency_penalty": 0,
  "tools": [
    {
      "type": "function",
      "function": {
        "name": "string",
        "description": "string",
        "parameters": {}
      }
    }
  ],
  "tool_choice": "string",
  "session_id": "string"
}
response = requests.request("POST", url, json = body, headers = {
  "Authorization": "Bearer <token>",
  "Content-Type": "application/json"
})

print(response.text)
null
{
  "detail": [
    {
      "loc": [
        "string"
      ],
      "msg": "string",
      "type": "string"
    }
  ]
}

How is this guide?