Local models in your code.

Connect Ollama models to your apps through an OpenAI-compatible local API. Get started with curl, Node.js or Python.

Download codef
The codef agent shows a CSS diff and an option to undo the edit

Local API

Run the API on your computer.

In codef, open Settings → Models and API → Local API and select Start.

Save the server key in CODEF_API_KEY, then request the model list.

macOS / Linux

curl -H "Authorization: Bearer $CODEF_API_KEY" \
  http://127.0.0.1:1234/v1/models

Windows PowerShell

curl.exe -H "Authorization: Bearer $env:CODEF_API_KEY" `
  http://127.0.0.1:1234/v1/models
Local API setup guide

Developer resources

Replace MODEL_ID with an identifier from GET /v1/models to get a response.

POST /v1/chat/completions

Node.js

example.mjs
const response = await fetch(
  "http://127.0.0.1:1234/v1/chat/completions",
  {
    method: "POST",
    headers: {
      Authorization: "Bearer " + process.env.CODEF_API_KEY,
      "Content-Type": "application/json",
    },
    body: JSON.stringify({
      model: "MODEL_ID",
      messages: [{ role: "user", content: "Hello!" }],
    }),
  },
);
if (!response.ok) throw new Error(await response.text());
const { choices } = await response.json();
console.log(choices[0].message.content);

Python

example.py
import json
import os
from urllib.request import Request, urlopen

payload = {
    "model": "MODEL_ID",
    "messages": [{"role": "user", "content": "Hello!"}],
}
request = Request(
    "http://127.0.0.1:1234/v1/chat/completions",
    data=json.dumps(payload).encode("utf-8"),
    headers={
        "Authorization": "Bearer " + os.environ["CODEF_API_KEY"],
        "Content-Type": "application/json",
    },
)
with urlopen(request) as response:
    print(json.load(response)["choices"][0]["message"]["content"])