Martian Model Router
  • Getting Started
    • Introduction
    • Hello World
    • Integrating Router
      • OpenAI Python
      • OpenAI Node
      • OpenAI cURL
      • LangChain Python
      • LangChain JS
    • Benchmarking Router
    • Router Parameters
    • Supported Models
Powered by GitBook
On this page
  1. Getting Started
  2. Integrating Router

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();
PreviousOpenAI PythonNextOpenAI cURL

Last updated 11 months ago