VERIFICATIONEndpoints and options checked against the current Ollama API, Chat, and Structured Outputs documentation.

30-SECOND SUMMARY

What to take away

  • The default local base URL is `http://localhost:11434/api`.
  • Use `/api/chat` for messages and begin with `stream:false` while developing.
  • Validate structured output in your application; a JSON schema does not guarantee factual accuracy.
REQUEST 01

A local API request

Validate complete responses before adding streaming.

  1. 01
    APP

    Build the request

  2. 02
    LOCALHOST

    Port 11434

  3. 03
    MODEL

    Local inference

  4. 04
    VALIDATE

    Check response

Use it this way Handle timeouts, cancellation, missing models, and invalid output explicitly.
SECTION 01

Make the smallest request

Confirm that the server and model work with curl before adding a framework. The local and cloud API base URLs are different, so verify that sensitive prompts point to localhost.

The working rule for “Make the smallest request” is: The default local base URL is `http://localhost:11434/api`. Exercise invalid input and interruption paths as well as the happy path, because application boundaries are where a working example most often fails.

After running the command or code, inspect the exit status, logs, and the file, process, or response it was meant to create. If it fails, change one input, version, permission, or resource condition at a time and repeat the same check so that the cause remains attributable.

curl http://localhost:11434/api/generate -d '{
  "model": "gemma3:4b",
  "prompt": "Explain local AI in one sentence.",
  "stream": false
}'
SECTION 02

Manage chat history explicitly

The chat endpoint accepts role-based messages. Your application should send the history required for each request rather than assuming the server remembers every conversation.

Summarize old turns or begin a new session when context becomes unnecessarily long.

Preserve the before-and-after state and the time of the check so that another run can reproduce the result. Include at least one failure condition—such as empty input, constrained resources, or a restart—to reveal the boundary of the step rather than documenting only the happy path.

SECTION 03

Add streaming after correctness

Streaming improves perceived latency but requires the client to assemble chunks, handle cancellation, and surface mid-stream failures.

Begin with a complete non-streaming response, validate the shape, and add streaming only when the basic flow is reliable.

Define completion with an observable result instead of a general impression. Repeat the same input, and if the output changes, isolate whether the model, runtime settings, or source data changed before moving to the next stage.

SECTION 04

Validate structured output

Structured Outputs can constrain a response with a JSON schema. A lower temperature can improve repeatability.

Still validate parsing, required fields, value ranges, and factual claims against the source data.

Use the checklist with a date and observed result beside every item. When one check fails, record its scope before continuing, then repeat the same input after the change; that turns a list of advice into evidence that the step actually works in this environment.

  • Define required fields
  • Limit retries
  • Validate ranges and lengths
  • Log validation errors without storing sensitive prompts
  • Provide a human-review path
SECTION 05

Design for failure

Handle a stopped server, missing model, timeout, oversized request, user cancellation, and invalid JSON. Do not retry indefinitely.

Keep the server on localhost unless you have designed authentication, TLS, access controls, monitoring, and rate limits.

Preserve the before-and-after state and the time of the check so that another run can reproduce the result. Include at least one failure condition—such as empty input, constrained resources, or a restart—to reveal the boundary of the step rather than documenting only the happy path.

FAQ

Frequently asked questions

Can I use any programming language?

Yes. Any language that can send HTTP requests can call the API; official Python and JavaScript libraries are also available. For a practical check, follow the “Make the smallest request” section, change one condition at a time, and record the result.

Does local API use cost money?

Local inference has no per-request Ollama API fee, but hardware and electricity still have costs. Cloud models have separate terms. For a practical check, follow the “Manage chat history explicitly” section, change one condition at a time, and record the result.

Does JSON schema make the answer true?

No. It constrains structure, not factual correctness. For a practical check, follow the “Add streaming after correctness” section, change one condition at a time, and record the result.

Primary sources

Check the original documentation for version-specific details.

Ollama API Introduction Ollama Chat API Ollama Structured Outputs

READ NEXT

Local RAG: Search Your Documents with a Local LLMSummarize PDFs with Local AI