Call with the Anthropic SDK

This page assumes that your application already uses the Anthropic Python SDK. After completing it, the application receives one text response through the Genesis Messages shape.

For full integration details and usage boundaries, see Genesis SDK.

How the call progresses

The Anthropic client uses the Genesis origin/root as its service address and appends the Messages version path itself. A successful response keeps the Messages content-block shape. Read text from a content block rather than using the Chat Completions response shape.

Prepare the call

Prepare the following:

Required item

How to obtain it

Purpose on this page

Existing Anthropic Python SDK

Use the dependency already used by the application; this page does not install or select a version

Creates the client

Genesis origin/root

Obtain it from the Genesis connection information for the current environment

Client service address

Genesis personal access token

Obtain it from the Genesis connection information for the current environment

Client credential

Messages-capable model ID

Select one from the model information for the current environment or list models

Selects the model for this call

This client uses the personal-access-token authentication shape. A service-account API Key uses a different authentication header; use the HTTP instructions in Messages (Anthropic) when calling with a service account.

Send a Messages request

The following example creates a client and submits one user message. It reads the text result from the first content block.

import os

from anthropic import Anthropic

client = Anthropic(
    base_url=os.environ["GENESIS_ORIGIN"],
    api_key=os.environ["GENESIS_PERSONAL_ACCESS_TOKEN"],
)

message = client.messages.create(
    model=os.environ["GENESIS_MODEL_ID"],
    max_tokens=1024,
    messages=[
        {"role": "user", "content": "Explain data lineage in one sentence."},
    ],
)

print(message.content[0].text)

Printed text means that this Messages call returned. The model must support Messages. Streaming, image input, and tool calling depend on the selected model and current service configuration.

Next steps

Last updated on