APIZDocs

APIZ guide

Anthropic API

Use adapter ID anthropic for a provider speaking the native Messages protocol. APIZ preserves model names and request/response bytes. Each provider's capabilities need separate verification.

What This Adapter Supports

Logical endpointActionPurpose
POST /v1/messagesanthropic:messages:createNative JSON or SSE generation
POST /v1/messages/count_tokensanthropic:messages:count_tokensInput token counting

Both routes are available for new root-only connections. Previously saved endpoint restrictions remain enforced; new restrictions belong in Policy. Client custom tools, inline content, thinking blocks, and cache controls pass through in the native protocol. Tool definitions and stored file references pass through for provider validation.

Set http.base_url to the Anthropic SDK root before /v1, such as https://api.anthropic.com or the GLM root https://open.bigmodel.cn/api/anthropic. APIZ appends /v1/messages or /v1/messages/count_tokens. HTTPS is supported; HTTP is restricted to loopback for local development. This root convention differs from the OpenAI-compatible adapter.

Credential Boundary

Store the upstream key in the write-only credential field. Native connections use x-api-key. New root-only GLM connections use the adapter-owned Bearer default for the exact HTTPS GLM endpoint. Saved explicit modes remain honored. APIZ removes caller authentication, cookies, beta, and workspace overrides and injects the configured anthropic_version (default 2023-06-01).

Agents receive a separate APIZ Temporary Credential, normally prefixed sk-ant-apiz-. Both native x-api-key and Authorization bearer transport use core credential validation before Policy and decision-bound Secret Broker access. Upstream auth_mode:none still requires valid APIZ authentication.

Prepare The Upstream Credential

Create a provider key on the trusted management side. Confirm its model access and intended spending controls. Enter the GLM API root for a new GLM connection; its authentication convention is resolved by the adapter.

Consult the Anthropic API documentation and GLM integration guide for provider requirements. Never place an upstream key in a URL, Policy, label, or agent environment.

Web Console

  1. Open API Instances → Create API Instance → Anthropic API.
  2. Enter a name and review the prefilled API root; replace it for another provider.
  3. Enter the write-only API key. The adapter handles upstream authentication.
  4. Optionally attach a model or operation Policy.
  5. Enter Test model to check token counting. Run the connection test and save. The result covers only model discovery (OpenAI) or token counting (Anthropic), not generation or all provider capabilities. A provider without that diagnostic endpoint can still be tested with an explicit, bounded generation request; that request may incur provider charges.

CLI

Run in Bash on the trusted management machine:

apiz adapter explain anthropic
read -rsp "Upstream API key: " LLM_API_KEY && printf '\n'
printf '%s' "$LLM_API_KEY" | jq -Rs '{credential: .}' |
apiz -o json api create \
  --adapter anthropic --name team-messages \
  --config-json '{"http":{"base_url":"https://open.bigmodel.cn/api/anthropic"}}' \
  --credential-stdin
unset LLM_API_KEY

A custom root uses {"http":{"base_url":"https://llm.example.invalid/api/anthropic"}}. Older explicit provider/authentication settings continue to be honored. A loopback URL refers to the backend's machine, not necessarily your laptop.

Give An Agent Access

apiz -o json client create --name llm-agent
apiz client bind <client-id> --api-instance <api-instance-id> --alias llm
apiz client credentials create <client-id> --binding llm --ttl 1h --format json

The Web flow is Clients → Add Binding → Create Temporary Credentials. Select the Anthropic-compatible credential shape. In the Setup Manifest, endpoint is the native SDK base URL and auth.credential is the APIZ temporary key. The manifest retains the core bearer authentication type; x-api-key is an additional supported carrier for that same key. The sdk-args format emits native base_url and api_key constructor arguments.

Shell and dotenv emit ANTHROPIC_BASE_URL (the selected binding root without an added /v1) and ANTHROPIC_API_KEY (the temporary APIZ binding key). They also retain APIZ CLI bootstrap configuration and namespaced binding variables. The bootstrap token retains whole-group recovery authority. Select one Anthropic item at a time to avoid conflicting native environment variables. Upstream provider credentials and unrelated service endpoints are never inserted.

Use It From The Agent

Set APIZ_LLM_ENDPOINT and APIZ_TEMPORARY_CREDENTIAL from the Setup Manifest. Set LLM_MODEL to the allowed provider model. With the official Python anthropic package installed:

import os
from anthropic import Anthropic

client = Anthropic(
    base_url=os.environ["APIZ_LLM_ENDPOINT"],
    api_key=os.environ["APIZ_TEMPORARY_CREDENTIAL"],
)
message = client.messages.create(
    model=os.environ["LLM_MODEL"],
    messages=[{"role": "user", "content": "Say hello briefly."}],
    max_tokens=64,
)
for block in message.content:
    if block.type == "text":
        print(block.text)

Do not append /v1 to this SDK base URL. For streaming, use the SDK's client.messages.stream(...) context manager and its text_stream iterator. Generation can incur provider charges. Send system instructions using the native top-level system field, not a message with the system role.

Policy Actions And Resources

Both endpoints expose type:llm_model, endpoint, model, stream, and tool_count. Generation requires positive max_tokens, exposed to Policy as max_output_tokens. Token counting has no output limit. Prompts, tool arguments, and generated content are excluded from these fields.

The optional Allow one LLM model template applies to both endpoints. A scripted Policy can additionally bound generation:

if (ctx.resource.model !== "example-model") return api.deny("model_not_allowed");
if (ctx.resource.endpoint === "messages" &&
    ctx.resource.max_output_tokens > 256) return api.deny("output_limit_exceeded");
return api.allow("bounded_model_request");

Replace the model before binding. A per-request token parameter is not a monetary budget or an assertion about provider billing.

Connection Tests

The test sends a small native token-count request, using test_config.model or a target.model override. Success requires HTTP 200 and a nonnegative integer input_tokens. It does not generate text. Configure a model first; the count_tokens endpoint must be enabled and supported upstream.

The management connection-test endpoint requires a user session when the caller otherwise uses a scoped User API Key. For automation, issue a Temporary Credential and call native /v1/messages/count_tokens through its binding. SDK arguments can be recovered with the Credential Group's default APIZ Client API token; management-side setup rendering is also session-only for scoped keys.

Some compatible providers support Messages without token counting. A failed count test does not establish that generation is broken. Conversely, a count success does not establish streaming, tool execution, or model quality.

Evidence And Troubleshooting

Use request evidence to distinguish APIZ denial, secret release failure, and upstream failure. HTTP 200 alone is not protocol success. The bounded observer reports complete, failed, incomplete, or unknown. Native SSE completion requires start, stop reason, and message_stop events. Usage includes cumulative input/output and available cache token counters.

  • missing_anthropic_test_model: configure the connection-test model.
  • unsupported_anthropic_endpoint: check path, method, endpoint list, and query.
  • invalid_anthropic_output_limit: supply a positive integer max_tokens.
  • invalid_anthropic_messages: check roles, content blocks, and duplicate keys.
  • Provider validation errors: check provider support for the submitted tools and content types.
  • Upstream 401: check the API key and provider root. Older explicitly configured authentication modes remain in effect and can be inspected through the CLI.
  • Upstream 404: ensure the configured root does not already include /v1.

Observation is best-effort and does not alter forwarded bytes. Compressed or oversized responses can produce unknown; request Accept-Encoding: identity when testing native usage observation.

Current Limitations

There is no OpenAI translation, model discovery, model aliasing, provider failover, billing, OAuth, file-management endpoints, batches, or beta-header passthrough. Content blocks, stored file references, hosted tools, remote MCP, and container/context-management fields pass through within supported requests. Features requiring beta headers may still be unavailable.

APIZ does not provide per-Client isolation of upstream account resources or hosted tool permissions. Clients sharing an upstream credential share its provider-side permissions, including access to files and conversations. Use separate upstream credentials/accounts when that isolation is required. Passing a field through does not establish provider support for it.

JSON requests use the platform body ceiling (default 1 MiB, hard maximum 8 MiB), unique keys, and at most 64 levels of nesting. JSON response observation is bounded to 1 MiB and SSE observation to 64 KiB per event. Inline documents may exceed the request limit. Provider extension fields pass through; compatibility beyond tested operations requires separate acceptance.