Anthropic ChatCompletion

Anthropic ChatCompletion

Certified

Send chat messages with Claude

Calls the Anthropic Messages API with rendered inputs, optional system prompt, and sampling controls; defaults to maxTokens 1024 and temperature 1.0 while emitting token usage counters. Refer to the Anthropic Console Settings to create an API key and the Anthropic API documentation for more information.

yaml
type: io.kestra.plugin.anthropic.ChatCompletion

Chat completion using Claude.

yaml
id: anthropic_chat_completion
namespace: company.team

tasks:
  - id: chat_completion
    type: io.kestra.plugin.anthropic.ChatCompletion
    apiKey: "{{ secret('ANTHROPIC_API_KEY') }}"
    model: "claude-sonnet-4-6"
    maxTokens: 1024
    messages:
      - type: USER
        content: "What is the capital of Japan? Answer with a unique word and without any punctuation."

Code generation using Claude

yaml
id: anthropic_code_generation
namespace: company.team

tasks:
  - id: code_generation
    type: io.kestra.plugin.anthropic.ChatCompletion
    apiKey: "{{ secret('ANTHROPIC_API_KEY') }}"
    model: "claude-sonnet-4-6"
    maxTokens: 1500
    temperature: 0.3
    messages:
      - type: USER
        content: |
          Write a Python function that:
          1. Takes a list of numbers as input
          2. Filters out negative numbers
          3. Calculates the average of remaining positive numbers
          4. Returns the result rounded to 2 decimal places
          5. Include error handling for empty lists
          Also provide 3 test cases with expected outputs.

Conversation with follow-up context

yaml
id: anthropic_context_conversation
namespace: company.team

tasks:
  - id: code_generation
    type: io.kestra.plugin.anthropic.ChatCompletion
    apiKey: "{{ secret('ANTHROPIC_API_KEY') }}"
    model: "claude-sonnet-4-6"
    maxTokens: 800
    temperature: 0.5
    messages:
      - type: USER
        content: "Explain quantum computing in simple terms."
      - type: ASSISTANT
        content: "Quantum computing uses quantum mechanical phenomena like superposition and entanglement to process information differently than classical computers. Instead of bits that are either 0 or 1, quantum computers use quantum bits (qubits) that can exist in multiple states simultaneously."
      - type: USER
        content: "That is helpful! Can you give me a practical example of how this could be used in everyday life in the next 10 years?"

Chat completion with prompt caching

yaml
id: anthropic_cached_chat
namespace: company.team

tasks:
  - id: cached_chat
    type: io.kestra.plugin.anthropic.ChatCompletion
    apiKey: "{{ secret('ANTHROPIC_API_KEY') }}"
    model: "claude-sonnet-4-6"
    maxTokens: 1024
    promptCaching: true
    system: "You are a helpful assistant with extensive knowledge about Kestra, the open-source orchestration platform."
    messages:
      - type: USER
        content: "What are the key features of Kestra?"

Tool-assisted structured extraction

yaml
id: anthropic_structured_output
namespace: company.team

tasks:
  - id: extract_data
    type: io.kestra.plugin.anthropic.ChatCompletion
    apiKey: "{{ secret('ANTHROPIC_API_KEY') }}"
    model: "claude-sonnet-4-6"
    maxTokens: 1024
    messages:
      - type: USER
        content: |
          Extract the following information from this text:
          "John Doe is 30 years old and works as a Software Engineer in San Francisco."
    tools:
      - name: extract_person_info
        description: "Extract structured information about a person"
        input_schema:
          type: object
          properties:
            name:
              type: string
              description: "The person's full name"
            age:
              type: integer
              description: "The person's age"
            occupation:
              type: string
              description: "The person's job title"
            location:
              type: string
              description: "The person's location"
          required:
            - name
            - age
Properties

Anthropic API Key

Messages

Ordered chat turns rendered from properties; include at least one USER message.

Definitions
contentstring
typestring
Possible Values
ASSISTANTUSER

Model

Claude model name to invoke (e.g., claude-sonnet-4-6); must match an Anthropic model available to your API key.

Default1024

Max Tokens

Maximum tokens Anthropic can generate; defaults to 1024 if unset.

Reference (ref) of the pluginDefaults to apply to this task.

Defaultfalse

Prompt caching

Enable prompt caching to reduce costs and latency for repetitive prompts. When enabled, the API automatically caches the longest cacheable prefix of the request. Cached tokens are billed at a reduced rate. See the Anthropic prompt caching documentation for details.

System prompt

Optional system instructions applied to the whole conversation; rendered before sending to Claude.

Default1.0

Temperature

Sampling randomness; range 0.0–1.0 with default 1.0. Lower for deterministic replies.

Tools

Optional tools Claude can invoke; each entry needs a unique name, an optional description, and an input_schema JSON Schema that defines the parameters the tool accepts.

Definitions
descriptionstring

Tool description

Optional description of what the tool does.

inputSchemaobject

Input schema

JSON Schema object defining the expected parameters for the tool.

namestring

Tool name

Unique identifier for the tool (1-128 characters).

Top K

Samples only from the top K tokens for each step; leave unset to let the model choose.

Top P

Nucleus sampling cap; 0.1 keeps only tokens in top 10% probability mass.

Cache creation input tokens

Number of tokens written to the cache.

Cache read input tokens

Number of tokens read from the cache.

Assistant text extracted from the response

The full response from Claude

Stop reason

The reason the model stopped generating (e.g., end_turn, tool_use, max_tokens).

Tool uses

List of tools that Claude requested to use, if any.

Definitions
idstring

Tool use ID

Unique identifier for this tool use.

inputobject

Tool input

Parameters passed to the tool as a map.

namestring

Tool name

Name of the tool being called.

Unittoken

Number of tokens written to the prompt cache.

Unittoken

Number of tokens read from the prompt cache.

Unittoken

Number of input tokens processed by the model.

Unittoken

Number of output tokens generated by the model.