02 โ€” Usage

Drop-in replacement for the OpenAI SDK

Change the baseURL and everything else stays the same. Chat, streaming, and image generation all work out of the box.

Chat completions

Use the OpenAI SDK as you normally would. Same API, same response shape.

chat.ts
import OpenAI from "openai";

const client = new OpenAI({
  apiKey: "meow",
  baseURL: "http://localhost:8787/v1",
});

const chat = await client.chat.completions.create({
  model: "meowgpt",
  messages: [{ role: "user", content: "hello" }],
});

console.log(chat.choices[0].message.content);
response
Meow meow ๐Ÿฑ

Add delay_ms to control response latency. Default 300ms. Set to 0 for instant CI responses.

curl

terminal
$ curl http://localhost:8787/v1/chat/completions \
  -H "Content-Type: application/json" \
  -d '{"model":"meowgpt","messages":[{"role":"user","content":"hello"}]}'

{
  "id": "chatcmpl_mock",
  "choices": [{ "message": { "content": "Meow meow ๐Ÿฑ" } }]
}

Streaming

Server-Sent Events, same chunk format as OpenAI. Works with any SSE client.

stream.ts
const stream = await client.chat.completions.create({
  model: "meowgpt",
  messages: [{ role: "user", content: "hello" }],
  stream: true,
});

for await (const chunk of stream) {
  process.stdout.write(chunk.choices[0]?.delta?.content ?? "");
}
sse stream
data: {"id":"chatcmpl_mock","object":"chat.completion.chunk",...}
data: {"id":"chatcmpl_mock","object":"chat.completion.chunk",...}
data: [DONE]

Image generation

Test your image generation pipeline without hitting a real API. Returns deterministic SVG cat images.

image.ts
const image = await client.images.generate({
  model: "meowgpt",
  prompt: "a cat",
});

console.log(image.data[0].url);
// https://meowgpt.dev/mock-image.png

curl

No SDK required. MeowGPT speaks plain HTTP. Use curl, fetch, or any HTTP library.

terminal
$ curl http://localhost:8787/v1/models

{
  "object": "list",
  "data": [{ "id": "meowgpt", "object": "model", "owned_by": "meowgpt" }]
}