Chat Completions

The chat completions API is the core of Jobim.ai's offering. It's fully compatible with OpenAI's API, making migration seamless.

Basic Usage

JavaScript Example

const completion = await openai.chat.completions.create({
  model: 'jobim-jfactor-utility',
  messages: [
    { role: 'system', content: 'You are a helpful assistant.' },
    { role: 'user', content: 'Hello!' }
  ],
});

Parameters

ParameterTypeDescription
modelstringID of the model to use
messagesarrayThe messages to generate completions for
temperaturenumberSampling temperature (0-2)
max_tokensnumberMaximum tokens to generate
streambooleanWhether to stream the response

Advanced Examples

Streaming Response

const stream = await openai.chat.completions.create({
  model: 'jobim-jfactor-utility',
  messages: [{ role: 'user', content: 'Tell me a story' }],
  stream: true,
});

for await (const chunk of stream) {
  process.stdout.write(chunk.choices[0]?.delta?.content || '');
}

JSON Mode

const completion = await openai.chat.completions.create({
  model: 'jobim-jfactor-utility',
  messages: [{ role: 'user', content: 'Return data as JSON' }],
  response_format: { type: 'json_object' },
});