API 端点

默认端口:http://localhost:11434

端点说明
POST /api/chat对话接口
POST /api/generate文本生成
POST /api/embeddings向量嵌入
POST /v1/chat/completionsOpenAI 兼容

对话接口

curl http://localhost:11434/api/chat -d '{
"model": "llama3.1",
"messages": [{"role": "user", "content": "你好"}]
}'

生成接口

curl http://localhost:11434/api/generate -d '{
"model": "llama3.1",
"prompt": "写一首诗",
"stream": false
}'

OpenAI 兼容

curl http://localhost:11434/v1/chat/completions -d '{
"model": "llama3.1",
"messages": [{"role": "user", "content": "Hello"}]
}'

# Python OpenAI SDK
from openai import OpenAI
client = OpenAI(base_url="http://localhost:11434/v1", api_key="ollama")
response = client.chat.completions.create(
model="llama3.1",
messages=[{"role": "user", "content": "Hello"}]
)
上一页:Modelfile下一页:模型量化