Skip to content
Lovelace

OpenAI-Compatible API

Lattice Cloud accepts the OpenAI request shape for chat completions, embeddings, and audio transcription. Swap the base URL and the API key, and your existing OpenAI client code keeps working. The request can run on Lovelace-hosted capacity or on a user's paired personal runtime.

ts
// Before: OpenAI
import OpenAI from "openai";

const client = new OpenAI({ apiKey: process.env.OPENAI_API_KEY });

const response = await client.chat.completions.create({
  model: "<model-id>",
  messages: [{ role: "user", content: "Summarize this." }],
});
ts
// After: Lattice Cloud (same SDK, two lines changed)
import OpenAI from "openai";

const client = new OpenAI({
  apiKey: process.env.LOVELACE_API_KEY,
  baseURL: "https://lattice.uselovelace.com/v1",
});

const response = await client.chat.completions.create({
  model: "lovelace:llama-3.2-3b-instruct",
  messages: [{ role: "user", content: "Summarize this." }],
});

Endpoints#

EndpointWhat runs
POST /v1/chat/completionsAny text-generation model
POST /v1/embeddingsAny text-embeddings model
POST /v1/audio/transcriptionsAny speech-to-text model
POST /v1/audio/translationsAny speech-translation model

These are the only OpenAI-compatible routes. Anthropic and Groq request shapes are not accepted: there is no /v1/messages route.

What changes when you swap the base URL#

The request and response bodies use the OpenAI shape. The model name is the field that differs: lovelace:* names a model in the Lattice catalog rather than a specific vendor's model, and lattice:personal:<id> selects a paired personal runtime.

Streaming#

Set stream: true and the response arrives as server-sent events in the OpenAI chat.completion.chunk format, so streaming clients keep working. Today the gateway completes the request first and then sends the whole answer as one content chunk, followed by a final chunk with the finish reason. Your client does not receive the answer token by token yet.

Why drop-in matters#

Backend engineers already know the OpenAI SDK. Evaluating Lattice should not require learning a new client first.

Once you have confirmed it works with the SDK you already have, the Lovelace SDK (@reasonabletech/lattice-client) exposes typed helpers for catalog browsing, structured errors, idempotency, and personal runtime selection. The SDK quickstart shows the typed path, and personal runtimes explains how a lattice:personal:* model maps to a paired local daemon.

Authentication#

Send the credential as a bearer token. Two kinds work:

  • Developer API key. Requests are made on behalf of your Lovelace account, and your users see nothing.
  • Sign in with Lovelace OAuth access token. Your user authorizes your app once, and their requests run under their grant. See the Lattice Cloud SDK quickstart for the OAuth flow.

Sending a request to a personal runtime requires the user's OAuth access token, not a developer API key.

Personal runtime model IDs#

When you want a request to run on a user's paired local daemon, use the personal runtime model selector with the user's access token:

ts
const client = new OpenAI({
  apiKey: userAccessToken,
  baseURL: "https://lattice.uselovelace.com/v1",
});

const response = await client.chat.completions.create({
  model: "lattice:personal:lat_abc123",
  messages: [{ role: "user", content: "Run this on my local model." }],
});

The lat_abc123 value comes from the personal runtime resource your backend created or discovered. The gateway still receives an ordinary /v1/chat/completions request, but the selected runtime controls where the model work runs.

Next steps#

  • Grab a key at platform.uselovelace.com/api-keys and point your existing SDK at the base URL above.
  • Pair a local daemon with personal runtimes when the user's own machine should serve the request.
  • When you outgrow the OpenAI surface, switch to @reasonabletech/lattice-client for typed runtime selection and structured gateway errors.
  • Use the sample app to verify token-provider, runtime-selection, revocation, and private-only failure handling.
  • Use the local Lattice docs when you are configuring the daemon that serves a personal runtime.