Skip to content

Call the local model through the interface ​

Chatting in the terminal is just the beginning. If you want your own programs, or software that already supports OpenAI, to use the local DeepSeek, you need to use the interface.

Ollama has its interface open on http://localhost:11434 of your machine. It has its own native interface, and also a compatible interface with the same format as OpenAI's.

What you'll be able to do after this lesson ​

  • Call the native interface with curl
  • Call the local model with OpenAI's Python library
  • Tell which field holds the answer and which holds the thinking process

Before you start ​

Step 1: Call the native interface with curl ​

sh
curl http://localhost:11434/api/chat -d '{
  "model": "deepseek-r1:8b",
  "stream": false,
  "messages": [{"role": "user", "content": "用一句话介绍你自己。"}]
}'

You should see: a piece of JSON. The message we got in our real test contains two fields:

  • content: the answer, for example "Hello! I'm DeepSeek-R1, a helpful AI assistant..."
  • thinking: its thinking process

"stream": false makes it return the complete result at once; without it, the response streams back piece by piece.

  • I got JSON containing content

Step 2: Call it with OpenAI's Python library ​

Many programs were originally written for OpenAI. Ollama's compatible interface address is http://localhost:11434/v1/; replace the address in your program with it and you can use the local model.

First, install the library:

sh
pip install openai

Then write this file (you can also download it directly):

python
from openai import OpenAI

client = OpenAI(
    base_url="http://localhost:11434/v1/",
    api_key="ollama",  # 必须填,但 Ollama 不检查
)

reply = client.chat.completions.create(
    model="deepseek-r1:8b",
    messages=[{"role": "user", "content": "用一句话说明本地部署的好处。"}],
)
print(reply.choices[0].message.content)

Note from the official docs: this library requires an API Key, but Ollama ignores it, so just fill in anything.

You should see: an answer. In our real test (openai 3.51.0) we got:

text
Through local deployment, enterprises can independently control data security and privacy protection, optimize system performance according to actual needs, and fully control their IT infrastructure.
  • My Python program printed an answer

Step 3: Let other software use the local model ​

For software that supports a "custom OpenAI interface", just fill in these three items:

What to fill inFill in this
Interface address (Base URL)http://localhost:11434/v1/
API KeyFill in anything, for example ollama
Model namedeepseek-r1:8b (go by the name shown in ollama list)

Quiz timeAn app asks for an OpenAI API Key, but you want it to use a local Ollama. What should you enter as the Key?

Checkpoints ​

  • I got the native interface working with curl
  • I got the compatible interface working with OpenAI's Python library
  • I know the answer is in content, and the thinking process is in a separate field

Didn't work? ​

Connection refused. Ollama isn't running. Open the Ollama app, or run ollama serve on Linux.

Model not found. The model name must exactly match what's in ollama list, including the size after the colon.

Next section ​

Frequently asked questions.

gaodong.aiAboutPrivacyContact

Independent tutorials, not affiliated with any product mentioned. Product names and trademarks belong to their owners. Check official pages for prices and policies.