# How to Connect to Local Ollama

### Quick Answer

Connecting to local Ollama means accessing the server running at `http://localhost:11434`. You can connect through the command-line interface using `ollama run`, direct REST API calls with any HTTP client, or visual tools like Postman for testing. The server starts automatically with the Ollama app and requires no authentication for local connections. Knowing these connection patterns is essential if you’re integrating local models into your apps, agents, or workflows.

 | Method | Best for | Setup effort |
|---|---|---|
| CLI | Quick testing, automation | None |
| REST API | Custom app integration | Low |
| Postman | Debugging &amp; collaboration | Low |
| SDK/Code | Production integration | Medium |

[ Try Postman today →](https://identity.getpostman.com/signup)

 

  ### Table of Contents

- [Overview](#overview)
- [How Ollama's local server works](#how-ollamas-local-server-works)
- [Connecting through the command-line interface (CLI)](#connecting-through-the-command-line-interface-cli)
- [Connecting through Postman](#connecting-through-postman)
- [Connecting from code](#connecting-from-code)
- [Troubleshooting common issues](#troubleshooting-common-issues)
- [Configuring network access (Optional)](#configuring-network-access-optional)
- [Final thoughts](#final-thoughts)
 
 

## Overview

Ollama runs a local server on your machine. You can connect to it through the CLI, REST API, or Postman. This guide covers each method, explaining how the server works, how to verify connections, and how to troubleshoot common issues so your local models stay accessible and reliable.

## How Ollama's local server works

Ollama runs as a background server process on your machine, listening on a specific network address and port. By default:

 ```
http://localhost:11434
```

This is where both the Ollama CLI and API requests connect. The server starts automatically when you launch the Ollama desktop app or via a systemd service on Linux.

When you run the following command, the CLI client is actually sending HTTP requests to this local server:

 ```
ollama run llama3.2
```

Before connecting, verify that Ollama is responding:

 ```
# Check if Ollama server is up
curl http://localhost:11434/api/tags

# List running models
ollama ps
```

If you get an error, the server may not be running.

- **macOS**: Make sure the Ollama app is active in your menu bar.
- **Windows**: Check Task Manager for Ollama.exe.
- **Linux**: Use `systemctl status ollama` to verify the service.
 
## Connecting through the command-line interface (CLI)

The CLI is the simplest way to connect to Ollama locally. When you install Ollama, it automatically configures the CLI to point to your local server.

### Common commands

 ```
# Start an interactive chat
ollama run llama3.2

# Send a one-off prompt
ollama run llama3.2 "Explain what a REST API is in one sentence"

# Manage models
ollama list         # List downloaded models
ollama pull mistral # Download new model
ollama ps           # View running models
```

The CLI is ideal for quick testing, experimentation, or automation. It abstracts HTTP details, allowing you to focus on prompts and output.

## Connecting through the REST API

The [REST API](https://blog.postman.com/rest-api-examples/) gives you full programmatic control over your local Ollama instance. Understanding how to connect to local Ollama via the API is essential for building applications and custom integrations.

The base URL is always your localhost address:

 ```
http://localhost:11434
```

### Test the API

 ```
curl http://localhost:11434/api/tags
```

### Generate text

This endpoint handles single prompts, similar to how POST requests work for creating resources:

 ```
curl http://localhost:11434/api/generate -d '{
  "model": "llama3.2",
  "prompt": "Write a Python function to reverse a string",
  "stream": false
}'
```

### Chat example

For conversational interactions with message history:

 ```
curl http://localhost:11434/api/chat -d '{
  "model": "llama3.2",
  "messages": [
    { "role": "user", "content": "How do I connect to a local API?" }
  ],
  "stream": false
}'
```

**Tip**: `stream: true` streams the output token-by-token, which is perfect for interactive UIs or AI agent-driven workflows.

## Connecting through Postman

Postman provides a visual interface for exploring, testing, and debugging local APIs like Ollama's. When you're learning how to connect to local Ollama or troubleshooting connection issues, Postman's interface makes it easier to validate your setup.

### Example setup

1. Create a new collection called Ollama Local.
2. Add a request:
    
    
    - **Method**: POST
    - **URL**: `http://localhost:11434/api/chat`
    - **Headers**: `Content-Type: application/json`
    - **Body** (raw JSON):
 
 ```
{
  "model": "llama3.2",
  "messages": [
    { "role": "user", "content": "Testing Ollama connection from Postman" }
  ],
  "stream": false
}


```

3. Use environment variables for flexibility:
    
    
    - `ollama_base_url = http://localhost:11434`
    - `default_model = llama3.2`
 
Then reference them:

 ```
{{ollama_base_url}}/api/chat
```

### Why Postman helps

Postman reduces syntax errors, organizes requests, and stores examples and responses in one place. It's especially useful for collaboration and debugging because you can share your working local requests with teammates directly. The Collection Runner automates testing of multiple endpoints, ensuring stable Ollama server connections in various scenarios.

**Tip**: Local environments are perfect for testing Ollama without worrying about network exposure or credentials.

## Connecting from code

Once you understand how to connect to local Ollama through the CLI and API, integrating it into your applications is straightforward. These patterns are compatible with any language that supports HTTP.

### Python example:

 ```
import requests

OLLAMA_BASE_URL = "http://localhost:11434"

def test_connection():
    try:
        response = requests.get(f"{OLLAMA_BASE_URL}/api/tags")
        response.raise_for_status()
        return True
    except requests.exceptions.RequestException as e:
        print(f"Connection failed: {e}")
        return False

def generate_text(prompt, model="llama3.2"):
    response = requests.post(
        f"{OLLAMA_BASE_URL}/api/generate",
        json={"model": model, "prompt": prompt, "stream": False}
    )
    return response.json()["response"]
```

### JavaScript example:

 ```
const OLLAMA_BASE_URL = 'http://localhost:11434';

async function generateText(prompt, model = 'llama3.2') {
  const response = await fetch(`${OLLAMA_BASE_URL}/api/generate`, {
    method: 'POST',
    headers: { 'Content-Type': 'application/json' },
    body: JSON.stringify({ model, prompt, stream: false })
  });
  const data = await response.json();
  return data.response;
}
```

These connection patterns work across languages, whether you're using Go, Rust, Java, or any other language with HTTP capabilities.

## Troubleshooting common issues

 | Error | Likely cause | Fix |
|---|---|---|
| Connection refused | Ollama server not running | Restart Ollama or check system service status. |
| Address already in use | Port 11434 is occupied | Use `lsof -i :11434` (macOS/Linux) or `netstat -ano` (Windows) to find conflicting processes. |
| Model not found | Model not downloaded | Run `ollama pull llama3.2`. |
| Cannot connect from another device | Ollama only accepts local connections | Set `OLLAMA_HOST=0.0.0.0:11434` (use with caution). |
| Timeout errors | Model is still loading | Wait for the model to load (`ollama ps`) or increase the timeout in your code. |

## Configuring network access (Optional)

By default, Ollama binds to:

 ```
127.0.0.1:11434
```

This limits access to your local machine, which is the most secure configuration for local development.

To make your Ollama server accessible across your network (useful for testing from mobile devices, tablets, or other computers):

 ```
export OLLAMA_HOST=0.0.0.0:11434
```

**Tip**: Ollama has no built-in authentication. Only enable external access on trusted private networks, and protect your machine behind a firewall or VPN.

## Final thoughts

Connecting to local Ollama revolves around one core concept: accessing the REST API running on `localhost:11434`. Whether you use the CLI for fast prototyping, Postman for structured testing, or REST calls from your code, each method helps you interact confidently with your local models.

With a clear connection setup, you'll avoid configuration headaches and keep your local AI development workflow reliable and repeatable, especially as you scale experiments or automate agents.

**Next step**: Try saving your Ollama API requests as a [Postman Collection](https://www.postman.com/product/collections/) to reuse and share local test workflows across your team.