Set up Claude API access and run a first request

Create development API access, provide a credential securely to a Python process, and verify one Messages API response.

Prepare the account and development environment

Use your organization’s Claude Console workspace for development. Check billing or credits and the workspace policy before sending a request. This guide uses the direct Claude API, where the workspace determines the key and available model IDs.

  • Check whether the development workspace already has an approved API credential. Create a dedicated key there if your role and organization authorize it.
  • Provide the credential to the process as ANTHROPIC_API_KEY through your project’s secret manager or approved launcher. Keep the value out of committed files and terminal output.
  • Choose a model offered in your workspace. The sample uses the direct API model ID claude-sonnet-5-5 and supports a CLAUDE_MODEL override.

Install the Python SDK

Use a dedicated Python environment for the project. This command installs the official Anthropic SDK into the interpreter currently selected by python.

Code
python -m pip install anthropic

Send one request with synthetic data

Save this as first_message.py and run python first_message.py in the authorized process. A successful response prints an answer based on the sample and then an object with input and output token counts. The response is expected to identify Friday as the due date.

Code
import os
import anthropic

if not os.environ.get("ANTHROPIC_API_KEY"):
    raise SystemExit("Supply ANTHROPIC_API_KEY through your secret manager.")

client = anthropic.Anthropic()
message = client.messages.create(
    model=os.environ.get("CLAUDE_MODEL", "claude-sonnet-5-5"),
    max_tokens=256,
    messages=[{
        "role": "user",
        "content": "Note: Maya will send the checklist on Friday. What is the due day?",
    }],
)
print("".join(block.text for block in message.content if block.type == "text"))
print({"input": message.usage.input_tokens, "output": message.usage.output_tokens})

Troubleshoot the first request

If the SDK cannot import, run installation and execution with the same Python interpreter. A 401 points to the credential. A 403 calls for checking workspace permissions. A 404 can indicate that the model ID is wrong or unavailable to the workspace. Check the chosen workspace and model before retrying.

Claude API quickstart

Related reading

What is Claude?

Making API Calls