Call with the Anthropic SDK¶
This page is for applications that already use the Anthropic Python SDK. After completing it, the application receives a text response through Genesis.
1. Configure the service address and credential¶
Create a personal access token in Access credentials, or create a service-account API key with Genesis access, then set the environment variables:
export GENESIS_ORIGIN='https://token.moi.matrixorigin.cn'
export GENESIS_ACCESS_TOKEN='<your-access-credential>'
The Anthropic SDK appends /v1/messages to GENESIS_ORIGIN, so do not add /v1 here.
2. Get a model ID¶
Open a Messages-capable model in the Genesis model marketplace and copy its model ID. You can also call List models and select a model whose capabilities include messages.
Save the model ID as an environment variable:
export GENESIS_MODEL_ID='<model-id>'
3. Call example¶
This example sends one message through Messages. Genesis uses Bearer authentication, so pass the access credential through auth_token:
import os
from anthropic import Anthropic
client = Anthropic(
base_url=os.environ["GENESIS_ORIGIN"],
auth_token=os.environ["GENESIS_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)
On success, the program prints the first text content block.
Next steps¶
See Messages (Anthropic) for complete request parameters and response fields.