Connect Claude application to AIGP

SupportedPython 3.12+Anthropic Messages APILearning series · Part 1MODEL_CALL

Send a first Claude Messages API request, handle its response, and add a bounded AIGP model-call record without changing the request.

Last updated

1. Learning objective

Configure a Claude application

Send a first Claude Messages API request, handle its response, and add a bounded AIGP model-call record without changing the request.

  • Python 3.12+
  • Anthropic API key and a selected Claude model
  • Optional: a running, authenticated AIGP OSS API

2. Technical context

Understand evidence boundaries

A support assistant can answer a harmless release-checklist question. The application still needs a way to correlate the run and inspect operational facts without uploading its prompt or answer.

3. Run without AIGP

Run the API example

Run the direct Anthropic Python SDK example. The only required output is Claude’s model-generated answer and a caller-created execution ID.

terminal · lab
cd labs/agent-frameworks/anthropic/claude-api-basics-intg
python3 -m venv .venv
source .venv/bin/activate
python -m pip install -r requirements.txt
export ANTHROPIC_API_KEY=...
export CLAUDE_MODEL=...
python first_application.py

4. Configure AIGP

Configure AIGP tracking

Set AI_GOVERNANCE_BASE_URL, AI_GOVERNANCE_ORGANIZATION_ID, and AI_GOVERNANCE_PROJECT_ID, then rerun the same command. The optional adapter starts an Agent Execution, records one MODEL_CALL with bounded model/usage/status facts, and completes it.

Privacy boundary: retain bounded identifiers, lifecycle, status, timing, digests, and references only. Do not submit prompts, responses, tool arguments/results, credentials, or raw SDK payloads.

Authenticate local AIGP requests

Obtain a short-lived token

If your local OSS stack uses Keycloak, the organization and project headers are scope selectors, not authentication. Generate a token from the generated local OAuth client and pass it only through AI_GOVERNANCE_ACCESS_TOKEN for this terminal session.

terminal · local Keycloak token
# Run from the OSS repository after its local Keycloak stack is ready.
cd /path/to/ai-governance-oss
./servers.sh up

# This ignored file contains the local walkthrough client credentials.
# It does not contain an access token.
set -a
source .env.oauth.generated
set +a

# Mint one short-lived token in memory for this terminal only.
export AI_GOVERNANCE_ACCESS_TOKEN="$(
  uv run python -c 'from ai_governance.oauth import access_token_from_environment; print(access_token_from_environment())'
)"

# Return to the Claude lab. Its .env supplies Claude and AIGP scope settings.
cd /path/to/labs/agent-frameworks/anthropic/claude-api-basics-intg
set -a
source .env
set +a
python first_application.py

# Remove the in-memory token when the session is over.
unset AI_GOVERNANCE_ACCESS_TOKEN

Never commit, print, paste into a screenshot, or add the token to .env. For development-mode and production workload identities, see Developer Authentication.

5. Inspect execution evidence

Inspect execution evidence

When the API accepts delivery, retrieve the printed AIGP execution ID with GET /api/v1/agent-executions/{execution_id}. Confirm a MODEL_CALL and terminal status. Prompts, response text, credentials, and raw SDK payloads are intentionally absent.

Only use a Studio screenshot after a run has been completed and its route, tenant scope, and visible data have been verified. This guide does not substitute a conceptual image for product evidence.

Verified Studio record for the Claude Messages API example. The UI shows bounded execution evidence rather than prompt or response content.

6. Test failure handling

Test failure handling

Unset ANTHROPIC_API_KEY to verify the application exits before calling Claude. Point the optional AIGP URL at an unavailable address to verify that the non-protected Claude example reports evidence unavailable without changing its Claude behavior.

7. Technical boundaries

Understand system boundaries

  • Claude owns authentication to the model service and response generation.
  • The application owns request construction, error handling, and its execution identity.
  • AIGP accepts a bounded evidence record; it neither runs Claude nor retains the request or response.

8. Next step

Add a Claude tool

This is a documented integration boundary, not an implicit AIGP feature. Continue only with the capabilities explicitly marked ready in the learning path.

Back to developer guides