Skip to content

OpenAI SDK

Using the OpenAI SDK

  • Using pip install openai
  • Using npm i openai
from openai import OpenAI

client = OpenAI(
  base_url="https://llm.siraya.pro/v1",
  api_key="<API_KEY>",
)

completion = client.chat.completions.create(
  model="{{MODEL}}",
  messages=[
    {
      "role": "user",
      "content": "What is the meaning of life?"
    }
  ]
)

print(completion.choices[0].message.content)
import OpenAI from 'openai';

const openai = new OpenAI({
  baseURL: 'https://llm.siraya.pro/v1',
  apiKey: '<API_KEY>',
});

async function main() {
  const completion = await openai.chat.completions.create({
    model: '{{MODEL}}',
    messages: [
      {
        role: 'user',
        content: 'What is the meaning of life?',
      },
    ],
  });

  console.log(completion.choices[0].message);
}

main();