MelonsRun
Sdks

OpenAI-Compatible SDK

Use the official OpenAI SDKs against MelonsRun's /v1 routes

The API exposes OpenAI-compatible LLM routes under /v1. Use a write-capable sk- key for generation endpoints.

export OPENAI_API_KEY="sk-..."
export OPENAI_BASE_URL="https://api.melons.run/v1"
import OpenAI from "openai";

const client = new OpenAI({
  apiKey: process.env.OPENAI_API_KEY,
  baseURL: process.env.OPENAI_BASE_URL ?? "https://api.melons.run/v1",
});

const chat = await client.chat.completions.create({
  model: "gpt-4o-mini",
  messages: [{ role: "user", content: "Reply with exactly: ok" }],
});
console.log(chat.choices[0]?.message?.content);

const stream = await client.chat.completions.create({
  model: "gpt-4o-mini",
  messages: [{ role: "user", content: "Count to three." }],
  stream: true,
});
for await (const event of stream) {
  process.stdout.write(event.choices[0]?.delta?.content ?? "");
}

const embedding = await client.embeddings.create({
  model: "gpt-4o-mini",
  input: "embed this sentence",
});
console.log(embedding.data[0].embedding.length);

const response = await client.responses.create({
  model: "gpt-4o-mini",
  input: "Return a short greeting.",
});
console.log(response.output_text);

Supported operations

Chat completions, streaming chat completions, legacy completions, embeddings, and responses.

On this page