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"

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: '