SabaKore

Home / Articles / AI guides

Setting Up Your Own OpenAI-Compatible API: The Perks and the Work

How to expose a model you run yourself in a form that existing AI apps can call as they are, along with the benefits and cautions.

Ren, a junior infrastructure engineer

Ren

What does 'OpenAI-compatible API' mean? I'm not building my own OpenAI, right?
Procura, a cloud AI robot who explains

Procura

Right. It means making the model running on your own VPS usable through the same calling method as OpenAI's format. The app on the calling side can talk to it with the same code without caring whether the other end is an external service or your own server.

The good parts

  • You can switch to your own model just by changing the destination of an existing AI app
  • It becomes easier to call external APIs and your own model separately depending on the use
  • You can also use it such that you switch to your own model only while an external service is down
Ren, a junior infrastructure engineer

Ren

If the calling method is the same, switching over should be easy too!
Procura, a cloud AI robot who explains

Procura

Even with the same calling method, the quality and quirks of the answers you get back are different. Just because you can call it in the same format as a large external model doesn't mean you'll get the same answers. Please be sure to check this before you switch.

Cautions when exposing it

Creating a compatible window also means adding one more entrance that can be called from outside. If you expose it without setting a key, anyone can use your VPS's computing resources as much as they like. Even if you intend to use it only yourself, add authentication from the start.

  • Require authentication such as a token for calls
  • Before exposing it externally, finish checking that it works on your own machine first
  • Record usage so you can check for unexpected calls

A design that switches between several models

If you have a compatible window, you can swap just the model behind it without changing the code on the calling side. You can also absorb splits like sending light tasks to your own small model and hard tasks to a large external model inside this window. From the calling side, it looks as if you're always talking to the same party.

  • Route to different models behind the scenes depending on the kind of task
  • Even when you swap models, the calling code doesn't need to change
  • Recording which model responded makes later comparison easier
Procura, a cloud AI robot who explains

Procura

'Same format' is about ease of switching, which is different from 'same contents.' If you keep that difference in mind, a compatible API can be a quite flexible weapon.
Ren, a junior infrastructure engineer

Ren

If I really wanted to use it only when an external service is down, what should I prepare?
Procura, a cloud AI robot who explains

Procura

The most important thing is to prepare the switching procedure in advance. If you normally use the external API and switch to your own model only during an outage, then as long as the procedure is settled, you won't have to rewrite settings in a panic in the middle of the outage.

The format may differ slightly in places

Even when something is called 'compatible,' it isn't necessarily identical down to the finest fields. It's not unusual for only some of the fields your app uses to be unsupported, so before you switch, try the main ways you use it end to end and confirm it works as expected. Rather than switching everything at once, move over gradually starting with the uses with the least impact, and you'll notice unexpected problems more easily.

  • Try the main ways you use it end to end before switching in earnest
  • Move over gradually, starting with the uses with the least impact
  • If you find an unsupported field, don't force it; keep that use on the external API
Ren, a junior infrastructure engineer

Ren

Even with the same format, the contents are different. And don't forget authentication.

This article is translated from the Japanese original. If the two differ, the Japanese version is the one we keep up to date.