Skip to main content
POST
/
chat
/
completions
import { PetStoreAPI } from '@petstoreapi/sdk';

const client = new PetStoreAPI({
  accessToken: process.env.OAUTH_ACCESS_TOKEN
});

const completion = await client.chat.completions.create({
  messages: [
    { role: 'user', content: 'What should I know before adopting a cat?' }
  ],
  model: 'pet-advisor-1',
  stream: false
});

console.log(completion.choices[0].message.content);
"data: {\"id\":\"chatcmpl_abc123\",\"object\":\"chat.completion.chunk\",\"created\":1702648800,\"model\":\"pet-advisor-1\",\"choices\":[{\"index\":0,\"delta\":{\"role\":\"assistant\",\"content\":\"\"},\"finish_reason\":null}]}\n\ndata: {\"id\":\"chatcmpl_abc123\",\"object\":\"chat.completion.chunk\",\"created\":1702648800,\"model\":\"pet-advisor-1\",\"choices\":[{\"index\":0,\"delta\":{\"content\":\"Before\"},\"finish_reason\":null}]}\n\ndata: {\"id\":\"chatcmpl_abc123\",\"object\":\"chat.completion.chunk\",\"created\":1702648800,\"model\":\"pet-advisor-1\",\"choices\":[{\"index\":0,\"delta\":{\"content\":\" adopting\"},\"finish_reason\":null}]}\n\ndata: {\"id\":\"chatcmpl_abc123\",\"object\":\"chat.completion.chunk\",\"created\":1702648800,\"model\":\"pet-advisor-1\",\"choices\":[{\"index\":0,\"delta\":{\"content\":\" a\"},\"finish_reason\":null}]}\n\ndata: {\"id\":\"chatcmpl_abc123\",\"object\":\"chat.completion.chunk\",\"created\":1702648800,\"model\":\"pet-advisor-1\",\"choices\":[{\"index\":0,\"delta\":{\"content\":\" cat\"},\"finish_reason\":null}]}\n\ndata: {\"id\":\"chatcmpl_abc123\",\"object\":\"chat.completion.chunk\",\"created\":1702648800,\"model\":\"pet-advisor-1\",\"choices\":[{\"index\":0,\"delta\":{\"content\":\"...\"},\"finish_reason\":null}]}\n\ndata: {\"id\":\"chatcmpl_abc123\",\"object\":\"chat.completion.chunk\",\"created\":1702648800,\"model\":\"pet-advisor-1\",\"choices\":[{\"index\":0,\"delta\":{},\"finish_reason\":\"stop\"}]}\n\ndata: [DONE]\n\n"
{
"type": "https://petstoreapi.com/errors/bad-request",
"title": "Bad Request",
"status": 400,
"detail": "Invalid value for parameter 'status'. Must be one of: available, pending, sold.",
"instance": "/pets"
}
{
"type": "https://petstoreapi.com/errors/unauthorized",
"title": "Unauthorized",
"status": 401,
"detail": "Authentication is required to access this resource. Please provide a valid OAuth 2.0 token."
}
{
"type": "https://petstoreapi.com/errors/validation-error",
"title": "Validation Error",
"status": 422,
"detail": "The request body contains validation errors.",
"instance": "/pets",
"errors": [
{
"field": "name",
"message": "Pet name is required",
"code": "required_field"
},
{
"field": "status",
"message": "Invalid status value",
"code": "invalid_format"
}
]
}
{
"type": "https://petstoreapi.com/errors/rate-limit-exceeded",
"title": "Too Many Requests",
"status": 429,
"detail": "Rate limit exceeded. Please wait 60 seconds before making another request."
}

Authorizations

Authorization
string
header
required

Bearer token authentication using JWT (JSON Web Token). Include the token in the Authorization header as: Authorization: Bearer <token>

Body

application/json
messages
object[]
required

A list of messages comprising the conversation so far

Minimum array length: 1
model
enum<string>
default:PET_ADVISOR_1

ID of the model to use

Available options:
PET_ADVISOR_1,
PET_ADVISOR_TURBO
stream
boolean
default:true

If true, partial message deltas will be sent via Server-Sent Events

maxTokens
integer
default:1024

Maximum number of tokens to generate

Required range: 1 <= x <= 4096
temperature
number
default:1

Sampling temperature between 0 and 2

Required range: 0 <= x <= 2

Response

Successful response. Format depends on the stream parameter.

Streaming response (when stream=true). Each line contains a JSON chunk prefixed with 'data: '