B2BB2B LLM

Anthropic client integration

Configure the native Messages client without duplicating the version path.

The Anthropic client appends the Messages path itself. Its base_url is the API origin, without a trailing /v1. Use a dedicated credential and a model that accepts the native Messages protocol.

python -m pip install anthropic
export B2B_API_KEY='mg_live_...'
import os
from anthropic import Anthropic

client = Anthropic(api_key=os.environ['B2B_API_KEY'],
                   base_url='https://api.b2b-llm.com')
message = client.messages.create(
    model='claude-sonnet-4.6', max_tokens=256,
    system='Use a professional, factual tone.',
    messages=[{'role': 'user', 'content': 'Draft a brief maintenance notice.'}]
)
for block in message.content:
    if block.type == 'text':
        print(block.text)

This reads text blocks rather than assuming a single string response. Tool and document blocks need the native structures supported by the SDK/model. Never place a system role inside the Anthropic conversation list; use the top-level parameter as above.

A 401 requires checking the credential and API origin. A 400 about messages or content fields usually requires inspecting the protocol shape rather than changing the company pricing template. Verify a minimal text request before adding attachments, thinking or tools.