Start the server
- Install a local model and start Ollama if it is installed separately.
-
Open Settings → Models and API → Local API and select Start. The
default base URL is
http://127.0.0.1:1234/v1. Set another port before starting if needed. -
Copy the key and send it in the
Authorization: Bearer …header. Copy a new key after restarting the server.
The server listens on this computer and stops when codef quits. Each request contains its own list of text messages.
Find the model ID
Replace CODEF_KEY with your key. On Windows you can
use curl.exe.
curl -H "Authorization: Bearer CODEF_KEY" http://127.0.0.1:1234/v1/models
Copy the model’s exact id and use it in place of
MODEL_ID.
Get a response
Save this UTF-8 request body as request.json.
{
"model": "MODEL_ID",
"messages": [
{"role": "user", "content": "Write a short greeting."}
]
}
Send the request from the same directory.
curl -H "Authorization: Bearer CODEF_KEY" -H "Content-Type: application/json" --data-binary "@request.json" http://127.0.0.1:1234/v1/chat/completions
The response text is in choices[0].message.content.
Add "stream": true and pass -N to curl
for SSE streaming. Use
"stream_options": {"include_usage": true} for token
usage at the end of the stream.
Supported endpoints and parameters
-
GET /v1/modelslists installed Ollama models. Read the identifier fromdata[].id. -
POST /v1/chat/completionsacceptsmodelandmessages. It supports text messages with thesystem,developer,user, andassistantroles. -
temperaturefrom 0 to 2 andtop_pfrom 0 to 1 control sampling.stopaccepts up to four sequences that end generation.
In a Chat Completions client, enter the base URL shown in codef and the local key. Use a single text completion. Agent tools, images, and embedding endpoints are unavailable through this server. See the Node.js and Python examples.
Request limits
A request can contain up to 128 text messages and use up to 256
KiB. Set max_completion_tokens or
max_tokens to a value from 1 to 8192. The default is
2048. The server runs up to two generations at once.
Resolve request errors
401. Copy the key from the running server.-
404 model_not_found. Check the model ID againstGET /v1/models. - Connection failed. Check that the server is running and that the port matches its base URL.