
Ollama Has a Free API — Here's How to Run LLMs Locally and Query Them
Ollama lets you run large language models locally on your machine. It provides a REST API compatible with OpenAI's format — completely free, no API keys needed. Installation curl -fsSL https://ollama.com/install.sh | sh # or download from ollama.com Pull and Run Models # Pull a model ollama pull llama3.2 ollama pull codellama ollama pull mistral # Chat in terminal ollama run llama3.2 "Explain web scraping in 3 sentences" REST API — Generate const response = await fetch ( " http://localhost:11434/api/generate " , { method : " POST " , body : JSON . stringify ({ model : " llama3.2 " , prompt : " Write a Python function to scrape a webpage " , stream : false }) }); const data = await response . json (); console . log ( data . response ); Chat API (OpenAI Compatible) const response = await fetch ( " http://localhost:11434/v1/chat/completions " , { method : " POST " , headers : { " Content-Type " : " application/json " }, body : JSON . stringify ({ model : " llama3.2 " , messages : [ { role
Continue reading on Dev.to JavaScript
Opens in a new tab

