Ollama, mevcut uygulamaları Ollama'ya bağlamak için, Claude Code gibi araçlar dahil, Anthropic Messages API ile uyumluluk sağlar.
Kullanım
Ortam değişkenleri
Anthropic API'sini bekleyen araçlarla (Claude Code gibi) Ollama'yi kullanmak için bu ortam değişkenlerini ayarlayın:
shell
export ANTHROPIC_AUTH_TOKEN=ollama # gerekli ancak yok sayılır
export ANTHROPIC_BASE_URL=http://localhost:11434Basit /v1/messages örneği
python
client = anthropic.Anthropic(
base_url='http://localhost:11434',
api_key='ollama', # gerekli ancak yok sayılır
)
message = client.messages.create(
model='qwen3-coder',
max_tokens=1024,
messages=[
{'role': 'user', 'content': 'Hello, how are you?'}
]
)
print(message.content[0].text)javascript
const anthropic = new Anthropic({
baseURL: "http://localhost:11434",
apiKey: "ollama", // gerekli ancak yok sayılır
});
const message = await anthropic.messages.create({
model: "qwen3-coder",
max_tokens: 1024,
messages: [{ role: "user", content: "Hello, how are you?" }],
});
console.log(message.content[0].text);shell
curl -X POST http://localhost:11434/v1/messages \
-H "Content-Type: application/json" \
-H "x-api-key: ollama" \
-H "anthropic-version: 2023-06-01" \
-d '{
"model": "qwen3-coder",
"max_tokens": 1024,
"messages": [{ "role": "user", "content": "Hello, how are you?" }]
}'Akış örneği
python
client = anthropic.Anthropic(
base_url='http://localhost:11434',
api_key='ollama',
)
with client.messages.stream(
model='qwen3-coder',
max_tokens=1024,
messages=[{'role': 'user', 'content': 'Count from 1 to 10'}]
) as stream:
for text in stream.text_stream:
print(text, end='', flush=True)javascript
const anthropic = new Anthropic({
baseURL: "http://localhost:11434",
apiKey: "ollama",
});
const stream = await anthropic.messages.stream({
model: "qwen3-coder",
max_tokens: 1024,
messages: [{ role: "user", content: "Count from 1 to 10" }],
});
for await (const event of stream) {
if (
event.type === "content_block_delta" &&
event.delta.type === "text_delta"
) {
process.stdout.write(event.delta.text);
}
}shell
curl -X POST http://localhost:11434/v1/messages \
-H "Content-Type: application/json" \
-d '{
"model": "qwen3-coder",
"max_tokens": 1024,
"stream": true,
"messages": [{ "role": "user", "content": "Count from 1 to 10" }]
}'Araç çağırma örneği
python
client = anthropic.Anthropic(
base_url='http://localhost:11434',
api_key='ollama',
)
message = client.messages.create(
model='qwen3-coder',
max_tokens=1024,
tools=[
{
'name': 'get_weather',
'description': 'Get the current weather in a location',
'input_schema': {
'type': 'object',
'properties': {
'location': {
'type': 'string',
'description': 'The city and state, e.g. San Francisco, CA'
}
},
'required': ['location']
}
}
],
messages=[{'role': 'user', 'content': "What's the weather in San Francisco?"}]
)
for block in message.content:
if block.type == 'tool_use':
print(f'Tool: {block.name}')
print(f'Input: {block.input}')javascript
const anthropic = new Anthropic({
baseURL: "http://localhost:11434",
apiKey: "ollama",
});
const message = await anthropic.messages.create({
model: "qwen3-coder",
max_tokens: 1024,
tools: [
{
name: "get_weather",
description: "Get the current weather in a location",
input_schema: {
type: "object",
properties: {
location: {
type: "string",
description: "The city and state, e.g. San Francisco, CA",
},
},
required: ["location"],
},
},
],
messages: [{ role: "user", content: "What's the weather in San Francisco?" }],
});
for (const block of message.content) {
if (block.type === "tool_use") {
console.log("Tool:", block.name);
console.log("Input:", block.input);
}
}shell
curl -X POST http://localhost:11434/v1/messages \
-H "Content-Type: application/json" \
-d '{
"model": "qwen3-coder",
"max_tokens": 1024,
"tools": [
{
"name": "get_weather",
"description": "Get the current weather in a location",
"input_schema": {
"type": "object",
"properties": {
"location": {
"type": "string",
"description": "The city and state"
}
},
"required": ["location"]
}
}
],
"messages": [{ "role": "user", "content": "What is the weather in San Francisco?" }]
}'Claude Code ile Kullanım
Claude Code Ollama'yi arka uç olarak kullanacak şekilde yapılandırılabilir.
Önerilen modeller
Kodlama kullanım senaryoları için glm-4.7, minimax-m2.1 ve qwen3-coder gibi modeller önerilir.
Kullanmadan önce bir model indirin:
shell
ollama pull qwen3-coderNot: Qwen 3 coder, sorunsuz çalışması için en az 24GB VRAM gerektiren 30B parametreli bir modeldir. Daha uzun bağlam uzunlukları için daha fazlası gerekir.
shell
ollama pull glm-4.7:cloudHızlı kurulum
shell
ollama launch claudeBu, bir model seçmenizi, Claude Code'u otomatik olarak yapılandırmanızı ve başlatmanızı ister. Başlatmadan yapılandırmak için:
shell
ollama launch claude --configManuel kurulum
Ortam değişkenlerini ayarlayın ve Claude Code'u çalıştırın:
shell
ANTHROPIC_AUTH_TOKEN=ollama ANTHROPIC_BASE_URL=http://localhost:11434 claude --model qwen3-coderVeya ortam değişkenlerini kabuk profilinizde ayarlayın:
shell
export ANTHROPIC_AUTH_TOKEN=ollama
export ANTHROPIC_BASE_URL=http://localhost:11434Ardından herhangi bir Ollama modeli ile Claude Code'u çalıştırın:
shell
claude --model qwen3-coderUç noktalar
/v1/messages
Desteklenen özellikler
- [x] Messages
- [x] Streaming
- [x] System prompts
- [x] Multi-turn conversations
- [x] Vision (images)
- [x] Tools (function calling)
- [x] Tool results
- [x] Thinking/extended thinking
Desteklenen istek alanları
- [x]
model - [x]
max_tokens - [x]
messages- [x] Text
content - [x] Image
content(base64) - [x] Array of content blocks
- [x]
tool_useblocks - [x]
tool_resultblocks - [x]
thinkingblocks
- [x] Text
- [x]
system(string or array) - [x]
stream - [x]
temperature - [x]
top_p - [x]
top_k - [x]
stop_sequences - [x]
tools - [x]
thinking - [ ]
tool_choice - [ ]
metadata
Desteklenen yanıt alanları
- [x]
id - [x]
type - [x]
role - [x]
model - [x]
content(text, tool_use, thinking blocks) - [x]
stop_reason(end_turn, max_tokens, tool_use) - [x]
usage(input_tokens, output_tokens)
Akış olayları
- [x]
message_start - [x]
content_block_start - [x]
content_block_delta(text_delta, input_json_delta, thinking_delta) - [x]
content_block_stop - [x]
message_delta - [x]
message_stop - [x]
ping - [x]
error
Modeller
Ollama hem yerel hem de bulut modellerini destekler.
Yerel modeller
Kullanmadan önce bir yerel model çekin:
shell
ollama pull qwen3-coderÖnerilen yerel modeller:
qwen3-coder- Kodlama görevleri için mükemmelgpt-oss:20b- Güçlü genel amaçlı model
Bulut modelleri
Bulut modelleri çekmeden hemen kullanılabilir:
glm-4.7:cloud- Yüksek performanslı bulut modeliminimax-m2.1:cloud- Hızlı bulut modeli
Varsayılan model adları
claude-3-5-sonnet gibi varsayılan Anthropic model adlarına güvenen araçlar için, mevcut bir model adını kopyalamak üzere ollama cp komutunu kullanın:
shell
ollama cp qwen3-coder claude-3-5-sonnetArdından bu yeni model adı model alanında belirtilebilir:
shell
curl http://localhost:11434/v1/messages \
-H "Content-Type: application/json" \
-d '{
"model": "claude-3-5-sonnet",
"max_tokens": 1024,
"messages": [
{
"role": "user",
"content": "Hello!"
}
]
}'Anthropic API'sinden Farklar
Davranış farklılıkları
- API anahtarı kabul edilir ancak doğrulanmaz
anthropic-versionbaşlığı kabul edilir ancak kullanılmaz- Token sayımları, temel alınan modelin tokenizer'ına dayalı yaklaşık değerlerdir
Desteklenmeyen özellikler
Aşağıdaki Anthropic API özellikleri şu anda desteklenmemektedir:
| Özellik | Açıklama |
|---|---|
/v1/messages/count_tokens | Token sayma uç noktası |
tool_choice | Belirli bir araç kullanımını zorlama veya araçları devre dışı bırakma |
metadata | İstek meta verileri (user_id) |
| Prompt caching | cache_control blokları ile önbelleğe alma önekleri |
| Batches API | /v1/messages/batches ile asenkron toplu işleme |
| Citations | citations içerik blokları |
| PDF support | PDF dosyaları ile document içerik blokları |
| Server-sent errors | Akış sırasında error olayları (hatalar HTTP durumu ile döndürülür) |
Kısmi destek
| Özellik | Durum |
|---|---|
| Image content | Base64 görseller desteklenir; URL görselleri desteklenmez |
| Extended thinking | Temel destek; budget_tokens kabul edilir ancak zorunlu değildir |