~/ / AI articles / Local LLMs on a VPS / Calling a local model from your code: structured outputs and the OpenAI-compatible API in Ollama
Calling a local model from your code: structured outputs and the OpenAI-compatible API in Ollama
Once Ollama runs on your server, your own code needs two things: a way to get answers in a fixed shape, and a way to reach the server from libraries that already speak the OpenAI API. Ollama documents both. This article summarizes the structured outputs page and the OpenAI compatibility page, and points out what the documentation says is not supported.
Published: · 4 min read · Checked against the official Ollama documentation on 2026-10-26. The supported features change between versions, so confirm them in the current documents.
Two ways to call the same server
Ollama has its own API, where the examples in the documentation POST to http://localhost:11434/api/chat. It also offers an OpenAI-compatible API under /v1/, so that existing OpenAI clients can talk to it by changing the base URL.
| Item | Native API | OpenAI-compatible API |
|---|---|---|
| Base address | http://localhost:11434/api/chat | http://localhost:11434/v1/ |
| API key | not mentioned in the examples | api_key='ollama', which the page marks as required but ignored |
| Structured output field | format | response_format |
The API key line comes from the documentation's local-server example. For the cloud, the page shows base_url https://ollama.com/v1 with an API key from your Ollama account, which is a different case.
Structured outputs: the format field
The format field constrains the response. It accepts the string json for generic JSON, or a JSON schema object. In the documentation's cURL examples the request body has four fields: model, messages, stream set to false, and format. The schema in the examples has type, properties and required.
| Value of format | Effect according to the documentation |
|---|---|
| "json" | The model answers with generic JSON |
| a JSON schema object | The response is constrained to that schema |
- The documentation says it is ideal to also pass the JSON schema as a string in the prompt, to ground the model's response.
- It also says to lower the temperature, for example to 0, for more deterministic completions.
- For Python and JavaScript it suggests defining schemas with Pydantic or Zod, so that they can be reused for validation.
- Vision models accept the same format parameter. The vision example in the documentation passes an image together with a schema.
- Ollama's cloud currently does not support structured outputs, according to the page.
Before you rely on a schema, check it. The JSON Schema Validator below tells you whether the schema itself is valid and whether a sample answer matches it.
Check the schema you send
A schema with a mistake can fail late, when the first request reaches the model. Paste the schema and a sample of the JSON you expect, and see whether they agree.
Try it: JSON Schema Validator
Follows JSON Schema Draft 2020-12 for the keywords it supports. It reads $ref only inside the same schema.
Everything runs in your browser. The schema and the data are not uploaded.
The OpenAI-compatible endpoints
| Endpoint | What the page lists | Listed as unsupported |
|---|---|---|
| /v1/chat/completions | chat, streaming, JSON mode, reproducible outputs, vision, tools, reasoning control | logprobs, tool_choice, logit_bias, user, n; image URLs (use base64) |
| /v1/completions | completions, streaming, JSON mode, reproducible outputs | logprobs, best_of, echo, logit_bias, user, n |
| /v1/models | list and retrieve models | not listed |
| /v1/embeddings | string or string-array input, encoding format, dimensions | token arrays, user |
| /v1/responses | streaming, function-calling tools, reasoning summaries | stateful requests: previous_response_id, conversation, truncation |
- On the chat endpoint the page lists these request fields among the supported ones: response_format, tools, stream, stream_options, seed, stop, temperature, top_p, max_tokens, frequency_penalty and presence_penalty.
- The page states that structured outputs work through the OpenAI-compatible API via response_format.
- If your code uses a field from the unsupported column, change the code instead of expecting the server to ignore it. The documentation does not say how each unsupported field is handled, apart from speech, where unsupported values return a 400 error.
Tools and the format of tool definitions
Both the native API and the OpenAI-compatible chat endpoint accept tools. If you describe tools in the OpenAI shape, the Tool Definition Checker on this site checks the names, descriptions and parameter schemas against that format before you send them.
When the answer is still not valid JSON
Constraining the output is meant to give you valid JSON, but your own code may still receive text from another model, an older version, or a request without format. The tool below repairs the common faults such as code fences, trailing commas and wrong quotes, and warns when a repair changes the meaning.
Try it: LLM JSON Repair
Only fixes with one clear answer are applied. Anything else is reported with its position instead of being guessed.
Everything runs in your browser. The text you paste is not uploaded.
A note on access
The documentation's local example says the API key is required but ignored. Our reading, not a statement from the documents: the key does not protect the server, so keep Ollama on its default address and put authentication in front of it if another machine must reach it.
Sources
Read next
- Open WebUI on a VPS: run it in Docker and connect it to OllamaRun Open WebUI with Docker and connect it to Ollama on your own server: the commands, the first account, the two connection types and how to update.
- What can a local model do? Tools, thinking, vision and embeddings in Ollama, and what fits on a VPSTools, thinking, vision, embeddings: what the labels in the Ollama library mean, which models carry them, and how big the downloads are.
- Install Ollama on a VPS and keep it running: install, systemd service, settings and updatesInstall Ollama on a Linux VPS and keep it running: the install command, the systemd service, environment variables, model storage and updates, from the official docs.
- How much memory does a local LLM need on a VPS? Model file plus KV cacheModel file plus KV cache: what the Ollama library, the Ollama FAQ and the official model configurations say about the memory a local LLM needs on a VPS.