OpenAI Node

Using OpenAI's SDK, the following function

import OpenAI from 'openai';

const openai = new OpenAI({
  apiKey: 'My OPENAI Key', // defaults to process.env["OPENAI_API_KEY"]
});

async function main() {
  const chatCompletion = await openai.chat.completions.create({
    model: 'gpt-3.5-turbo',
    messages: [{ role: 'user', content: 'Say this is a test' }],
  });
}

main();

becomes

import OpenAI from 'openai';

const openai = new OpenAI({
  apiKey: 'My Martian Key', // defaults to process.env["OPENAI_API_KEY"]
  baseURL: "https://withmartian.com/api/openai/v1"
});

async function main() {
  const chatCompletion = await openai.chat.completions.create({
    model: 'router',
    messages: [{ role: 'user', content: 'Say this is a test' }],
  });
}

main();

Last updated