Skip to content

Use with Anthropic

Terminal window
pip install prompty[jinja2,anthropic]

You also need an Anthropic API key.


Create anthropic-chat.prompty:

---
name: anthropic-chat
description: Chat completion with Anthropic Claude
model:
id: claude-sonnet-4-6
provider: anthropic
connection:
kind: key
endpoint: ${env:ANTHROPIC_ENDPOINT:https://api.anthropic.com}
apiKey: ${env:ANTHROPIC_API_KEY}
options:
temperature: 0.7
maxOutputTokens: 1024
inputs:
- name: topic
kind: string
default: the history of computing
template:
format:
kind: jinja2
parser:
kind: prompty
---
system:
You are a knowledgeable assistant who gives clear, concise explanations.
user:
Tell me about {{topic}}.

Create a .env file in the same directory:

.env
ANTHROPIC_API_KEY=sk-ant-your-key-here

import prompty
result = prompty.execute(
"anthropic-chat.prompty",
inputs={"topic": "quantum computing"}
)
print(result)

If you need more control, use the individual pipeline stages:

import prompty
# Load the prompt
agent = prompty.load("anthropic-chat.prompty")
# Render + parse → message list (no LLM call)
messages = prompty.prepare(agent, inputs={"topic": "quantum computing"})
print(messages) # inspect before sending
# Execute + process → final result
result = prompty.run(agent, messages)
print(result)

Anthropic’s Claude model family includes:

ModelBest for
claude-opus-4-0Complex reasoning, research, multi-step tasks
claude-sonnet-4-6Balanced performance and speed (recommended default)
claude-haiku-3-5Fast responses, simple tasks, lower cost

Change the model by updating model.id in your .prompty file:

model:
id: claude-haiku-3-5

If you’re using an Anthropic-compatible proxy or a different base URL, set the endpoint explicitly:

model:
connection:
kind: key
endpoint: https://my-proxy.example.com
apiKey: ${env:ANTHROPIC_API_KEY}

Or use an environment variable:

model:
connection:
kind: key
endpoint: ${env:ANTHROPIC_ENDPOINT}
apiKey: ${env:ANTHROPIC_API_KEY}

AspectOpenAIAnthropic
Providerprovider: openaiprovider: anthropic
Default endpointhttps://api.openai.com/v1https://api.anthropic.com
Model namesgpt-4o, gpt-4o-miniclaude-sonnet-4-6, claude-haiku-3-5
API key prefixsk-sk-ant-
Responses API✅ Supported❌ Not supported
Image generation✅ DALL-E❌ Not available