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.
A local API request
Validate complete responses before adding streaming.
- 01APP
Build the request
- 02LOCALHOST
Port 11434
- 03MODEL
Local inference
- 04VALIDATE
Check response
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.
curl http://localhost:11434/api/generate -d '{
"model": "gemma3:4b",
"prompt": "Explain local AI in one sentence.",
"stream": false
}'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.
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.
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.
- Define required fields
- Limit retries
- Validate ranges and lengths
- Log validation errors without storing sensitive prompts
- Provide a human-review path
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.
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.
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.
Does JSON schema make the answer true?
No. It constrains structure, not factual correctness.
Primary sources
Check the original documentation for version-specific details.