Checking how many agents are working

How this works
Contacto
← Blog
Two different dark steel plugs fitting the same round olive-lit socket on a panel, with the AMARBARO mark centered above it.
✎publicación de blog

What an OpenAI-compatible API means, and why it is handy

The short version

A shared request format lets one app talk to many models, local or hosted, without code written for each.

What this is about

When one program wants to talk to a model, it needs to know how to ask. The question has to come in a shape the model's server understands, and the answer has to come back in a shape the program understands. That agreed shape is an API.

Over time one shape became common. It was first made popular by OpenAI's chat service. Many other servers, including ours, copy it. We say such a server is "OpenAI-compatible". It does not mean it uses OpenAI's models. It means it speaks the same message format.

Why it matters

Think of a wall socket. If every country used a different plug, you would need a new lamp for each country. With one shape, any lamp works anywhere.

An app written for the common shape can use any compatible model. Switch from a hosted model to one on your own computer by changing one address. You do not rewrite the app. That is handy for trying a local model, for comparing models, and for not being locked in.

How it works

The idea is simple. The program sends a request, and the server sends back an answer. Both are small pieces of text in a format called JSON.

A chat request has a list of messages. Each message says who is speaking, in a field called role, and what they said, in a field called content. The role is user for you and assistant for the model. A request can also say how many tokens at most to write.

Here is a real request, from our README, sent to a model running on our own machine:

curl -s localhost:8080/v1/chat/completions -H 'content-type: application/json' -d '{
  "messages": [{"role": "user", "content": "Name the capital of France in one word."}],
  "max_tokens": 16000
}' | jq -r '.choices[0].message.content'

The answer comes back with a list called choices. The first choice has a message, and that message has the model's content. The last part of the command, .choices[0].message.content, picks exactly that out.

Two more parts of the shape are worth knowing.

  • Streaming. If you add stream: true, the server sends pieces of the answer as they are written, so you see words appear. This uses a standard web mechanism called server-sent events.
  • The base address. Programs that speak the common shape let you set a base address. Ours is http://localhost:8080/v1. Point any such program at it and it talks to our engine.

What our engine offers

mojo-baro, our engine, answers these routes:

  • POST /v1/chat/completions, the chat route above.
  • POST /v1/completions, for plain text continuation.
  • GET /v1/models, to list which model is loaded.
  • POST /v1/embeddings, which turns text into a list of numbers for searching by meaning.
  • Plus routes in the style of another popular local tool, Ollama, such as /api/chat and /api/tags, so programs written for that one work too.

It also has a few of its own, such as POST /v1/cancel to stop a request, and GET /health, which returns 200 only when an engine can take work.

How Yahaai uses it

Yahaai is our messenger where people and AI models share one chat log. A model there has a name of the form owner:model. By design, users bring their own models through any OpenAI-compatible endpoint, in a part of the app called My models, and can share them with contacts or everyone. Models speak only when someone mentions them, and the owner's key pays, so no credits are involved.

That is why the shared format matters to us. Yahaai does not need special code for each model. It needs an address and a key. We have not tested or documented in this article how a model on your home machine would be reached from a server on the internet. That is a network question, not an API question. The point here is only that the API shape is the same.

Limits of "compatible"

Compatible does not mean identical. Servers copy the common shape, but each one may leave out a field or add its own. Before you rely on a feature such as tool calls or structured output, test it on the server you will use. Our README lists what ours supports, including tool calls and JSON-schema masks, and it says which routes are ours and which copy others.

Compatible also says nothing about quality or speed. Two compatible servers can give very different answers and wait times.

Words you may not know

  • API: a set of rules that lets one program talk to another.
  • Endpoint: the address where a server offers part of its API.
  • JSON: a simple text format for structured data, with names and values.
  • Role: who is speaking in a message: user, assistant or system.
  • Streaming: getting the answer in pieces as it is written.
  • Base address: the start of the URL that a program uses for all its requests.
  • Embedding: a list of numbers that stands for the meaning of a piece of text.

Try it

  • Open Yahaai and look at how models and people share a chat.
  • Run the request above against your own server, if you have one, or read the full route list on the mojo-baro project page.
  • If you have any program that lets you set an "API base URL", point it at a server you run and see if it answers.
  • Beating llama.cpp at Decode, Without Speculating, which tests the same server against another popular engine.

Comentarios

Aún no hay comentarios.

Iniciar sesión para comentar.