Skip to main content

metorial-anthropic

Anthropic (Claude) provider integration for Metorial.

Installation

pip install metorial anthropic

Quick Start

import asyncio
from metorial import Metorial, MetorialAnthropic
from anthropic import AsyncAnthropic

metorial = Metorial(api_key="your-metorial-api-key")
anthropic = AsyncAnthropic(api_key="your-anthropic-api-key")

async def main():
    async def session_handler(session):
        messages = [{"role": "user", "content": "What's the latest news?"}]

        for _ in range(10):
            response = await anthropic.messages.create(
                model="claude-sonnet-4-5",
                max_tokens=1024,
                messages=messages,
                tools=session["tools"]
            )

            tool_calls = [b for b in response.content if b.type == "tool_use"]
            if not tool_calls:
                print(response.content[0].text)
                break

            tool_responses = await session["callTools"](tool_calls)
            messages.append({"role": "assistant", "content": response.content})
            messages.append(tool_responses)

        await session["closeSession"]()

    await metorial.with_provider_session(
        MetorialAnthropic,
        {"serverDeployments": [{"serverDeploymentId": "your-server-deployment-id"}]},
        session_handler
    )

asyncio.run(main())

Streaming

import asyncio
from metorial import Metorial, MetorialAnthropic
from anthropic import AsyncAnthropic

metorial = Metorial(api_key="your-metorial-api-key")
anthropic = AsyncAnthropic(api_key="your-anthropic-api-key")

async def main():
    async def session_handler(session):
        messages = [{"role": "user", "content": "What's the latest news?"}]

        for _ in range(10):
            async with anthropic.messages.stream(
                model="claude-sonnet-4-5",
                max_tokens=1024,
                messages=messages,
                tools=session["tools"]
            ) as stream:
                async for text in stream.text_stream:
                    print(text, end="", flush=True)
                response = await stream.get_final_message()

            tool_calls = [b for b in response.content if b.type == "tool_use"]
            if not tool_calls:
                print()
                break

            tool_responses = await session["callTools"](tool_calls)
            messages.append({"role": "assistant", "content": response.content})
            messages.append(tool_responses)

        await session["closeSession"]()

    await metorial.with_provider_session(
        MetorialAnthropic,
        {
            "serverDeployments": [{"serverDeploymentId": "your-server-deployment-id"}],
            "streaming": True,  # Required for streaming with tool calls
        },
        session_handler
    )

asyncio.run(main())

Supported Models

All Anthropic Claude models that support tool calling:

  • claude-sonnet-4-5: Latest Claude Sonnet
  • claude-opus-4: Most capable Claude model
  • claude-3-5-sonnet-20241022: Claude 3.5 Sonnet
  • claude-3-5-haiku-20241022: Fastest Claude 3.5 model

Session Object

async def session_handler(session):
    tools = session["tools"]           # Tool definitions in Anthropic format
    call_tools = session["callTools"]  # Execute tools and get responses
    close_session = session["closeSession"]  # Close the session when done

Error Handling

from metorial import MetorialAPIError

try:
    await metorial.with_provider_session(...)
except MetorialAPIError as e:
    print(f"API Error: {e.message} (Status: {e.status})")
except Exception as e:
    print(f"Unexpected error: {e}")

License

MIT License - see LICENSE file for details.

Metadata

Release files for metorial-anthropic 1.0.5

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for metorial-anthropic 1.0.5
File Size Uploaded
metorial_anthropic-1.0.5.tar.gz 7.2 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for metorial-anthropic 1.0.5
File Interpreter ABI Platform
metorial_anthropic-1.0.5-py3-none-any.whl Python 3 none any Details

Total release size: 13.3 kB

Release files / metorial_anthropic-1.0.5.tar.gz

Download URL metorial_anthropic-1.0.5.tar.gz
Size 7.2 kB
Tags Source
SHA-256 checksum
How to use checksums
9023ebed6ca5925ace95964fa694690bf7e6d8548463a1ead6f5d0bcb11d36d4
BLAKE2b-256 checksum
How to use checksums
ebee73f933e1c5ebe1ddfea5316d4d9983c17a033d08925d939c8bbf52110ae9
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.7

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Dec 23, 2025.

Transparency log

Release files / metorial_anthropic-1.0.5-py3-none-any.whl

Download URL metorial_anthropic-1.0.5-py3-none-any.whl
Size 6.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
bcefbd560da3b2eba13a2c9837f489ef71eb22dc52625cf98dca3b1fcb775e6c
BLAKE2b-256 checksum
How to use checksums
5af000a8f069a30277da8d0a0d9c583122eb91e66585488f6790b8e0b03bce36
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.7

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Dec 23, 2025.

Transparency log
Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page