Adapters
Anthropic
Learn how to use PromptL with Anthropic
Overview
PromptL integrates seamlessly with Anthropic’s API by using the Anthropic
adapter. This ensures prompts are formatted correctly for their API and Node.js SDK, allowing you to generate dynamic prompts with ease.
System Message Limitations: Anthropic does not support system messages in the messages array. Instead:
- PropmtL will automatically move the first system message to the
config
object. - System messages are not allowed after messages from other roles, and it will throw an error.
- Since system messages are moved to the configuration section, Anthropic will fail if there are no other user or assistant messages in the conversation.
Basic Example
Here’s how to use PromptL with Anthropic’s API:
Key Features
- Adapter-Specific Behavior:
- System messages are extracted and placed in the
config
object. - The
messages
array must contain non-system messages.
- System messages are extracted and placed in the
- Formatting: PromptL formats messages in the format expected by Anthropic, ensuring compatibility.
- Support for Claude Models: Works seamlessly with Anthropic’s Claude family of models.
Troubleshooting
- Empty Messages Array:
- Ensure your prompt contains non-system messages. Anthropic’s API does not allow an empty
messages
array.
- Ensure your prompt contains non-system messages. Anthropic’s API does not allow an empty
- Check Configuration:
- Anthropic always requires to define at least a
model
andmax_tokens
configuration.
- Anthropic always requires to define at least a
- Error Handling:
Next Steps
- Learn More About Anthropic’s API
- Explore advanced PromptL features: