
OpenAI's gpt-oss models brought open-weight reasoning models from OpenAI to anyone's hardware, released under the permissive Apache 2.0 license. The smaller gpt-oss-20b model runs on many consumer GPUs and Apple Silicon Macs, delivering strong reasoning and tool use completely offline. In this tutorial, you will run gpt-oss locally with Ollama step by step, check hardware requirements, chat with the model, use the Ollama API from Python, and connect existing OpenAI-compatible tools to your private llm setup.
Start with what the models are and what hardware you need.
About the gpt-oss Models
gpt-oss comes in two sizes:
gpt-oss-20b: about 21 billion total parameters with a mixture-of-experts design that activates only a few billion parameters per token. It runs within about 16GB of memory.
gpt-oss-120b: about 117 billion total parameters, designed to run on a single 80GB GPU.
Both use native 4-bit MXFP4 quantization for the expert weights, support adjustable reasoning effort, tool calling and structured outputs, and use OpenAI's harmony response format, which Ollama handles automatically.
gpt-oss-20b Requirements
For gpt-oss-20b requirements:
- Memory: at least 16GB of VRAM on a GPU, or 16GB or more of unified memory on an Apple Silicon Mac. More memory allows longer context.
- Disk space: roughly 14GB for the model download.
- Operating system: macOS, Windows or Linux.
The model can run with less GPU memory by offloading to system RAM, but speed drops significantly. For gpt-oss-120b, plan for an 80GB-class GPU or a high-memory workstation.
Step 1: Install Ollama
Download Ollama from its official website and run the installer for your operating system. On Linux, the website provides an install command.
After installation, open a terminal and run ollama --version to confirm it works. On macOS and Windows, Ollama runs as a background app with a small icon in the menu bar or system tray.
Step 2: Download and Run the Model
Run ollama pull gpt-oss:20b to download the model. Visual description: your terminal shows a progress bar as the model layers download, followed by a success message.
Then run ollama run gpt-oss:20b to start an interactive chat in the terminal. Type a question, such as explain the difference between a process and a thread, and press Enter. The model shows its reasoning, then the answer.
Type /bye to exit the chat.
Ollama also offers a desktop chat app on some platforms, giving you a graphical interface for the same local model.
Step 3: Adjust Reasoning Effort
gpt-oss supports low, medium and high reasoning effort. Lower effort gives faster answers for simple questions; higher effort improves complex reasoning. You can set reasoning effort through the system prompt, for example a line stating Reasoning: high, or through options supported by Ollama's API and apps. Check the current Ollama documentation for the preferred setting method, since it may evolve.
Step 4: Use the Ollama API
Ollama runs a local server on port 11434. This ollama api tutorial covers two ways to use it.
Native API: send a POST request to the chat endpoint at localhost port 11434 with a JSON body containing the model name and a list of messages. In Python, install the official library with pip install ollama, then call its chat function with the model name gpt-oss:20b and your messages. The response contains the assistant's message.
OpenAI-compatible API: Ollama exposes an endpoint compatible with OpenAI's chat completions API at localhost port 11434 under the v1 path. Install the OpenAI Python library and create a client with the base URL set to that local address and any placeholder string as the API key. Then call chat completions with model gpt-oss:20b.
The OpenAI-compatible endpoint is powerful: any tool or code written for OpenAI's API can now use a local openai model by changing only the base URL.
Step 5: Stream Responses
For better user experience, enable streaming by setting stream to true in either API. The response arrives token by token, which you can print as it is generated. Visual description: text appears progressively in your terminal rather than all at once after a pause.
Step 6: Use Tool Calling
gpt-oss supports function calling. Define tools with JSON schemas in your request, just as you would with OpenAI's API. When the model decides to call a tool, the response includes the tool name and arguments. Execute the function in your code, add the result to the messages and call the model again to get the final answer.
This makes gpt-oss suitable for local agents that work with files, databases or internal APIs without sending data to the cloud.
Step 7: Increase Context Length
Ollama uses a default context length that may be shorter than the model supports. For longer documents or conversations, increase the context setting through the model options in the API, Ollama's settings or a Modelfile. Larger contexts require more memory, so increase gradually and watch memory usage.
Step 8: Connect Other Tools
Because Ollama is widely supported, you can connect gpt-oss to:
- Open WebUI for a ChatGPT-like browser interface.
- Coding extensions such as Continue for private code assistance.
- Agent frameworks that support OpenAI-compatible endpoints.
- Automation platforms such as n8n.
Point each tool at your local Ollama address.
Troubleshooting Common Issues
Very slow generation: the model may be partly offloaded to CPU. Check GPU usage with ollama ps, close other GPU-heavy applications or reduce context length.
Out of memory errors: reduce context length or use a machine with more memory.
Connection refused from code: make sure Ollama is running; restart the app or run ollama serve.
Accessing from another machine: by default Ollama listens on localhost. Changing this exposes the API to your network without authentication, so place it behind a secured proxy if needed.
Outdated model behavior: update Ollama and re-pull the model to get fixes.
Privacy and Security Benefits
A private llm setup keeps prompts and documents on your hardware, which is valuable for confidential code, legal documents or personal data. Remember that local models still need application-level security, especially if you expose the API or give the model tools that act on your system.
Frequently Asked Questions
How does gpt-oss-20b compare with cloud models? It performs strongly for its size on reasoning and coding but trails the largest frontier models on the hardest tasks.
Can I use it commercially? The Apache 2.0 license permits commercial use, along with OpenAI's usage policy.
Conclusion
You have learned to run gpt-oss locally with Ollama: checking hardware, downloading and chatting with gpt-oss-20b, adjusting reasoning effort, using the native and OpenAI-compatible APIs, streaming, tool calling and increasing context.
Key takeaways: ensure at least 16GB of memory, use the OpenAI-compatible endpoint to reuse existing code, tune context for your hardware, and secure the API before exposing it. Next, connect gpt-oss to your editor or a local document assistant and compare it with your current cloud workflow.