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

Procura
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

Procura
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
Ren

Procura
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
This article is translated from the Japanese original. If the two differ, the Japanese version is the one we keep up to date.