> ## Documentation Index
> Fetch the complete documentation index at: https://concentrate.ai/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# Anthropic SDK

> Use the Anthropic Python or JavaScript SDK with Concentrate's Messages API.

Use the official Anthropic SDKs with Concentrate's [Messages API](/docs/api-reference/endpoint/create-message). Set the base URL to `https://api.concentrate.ai`.

## Install

<CodeGroup>
  ```bash Python theme={null}
  pip install anthropic
  ```

  ```bash JavaScript theme={null}
  npm install @anthropic-ai/sdk
  ```
</CodeGroup>

Set `CONCENTRATE_API_KEY` in your environment. Keep it on your server; do not expose it in browser code.

## Create a message

<CodeGroup>
  ```python Python theme={null}
  import os
  from anthropic import Anthropic

  client = Anthropic(
      api_key=os.environ["CONCENTRATE_API_KEY"],
      base_url="https://api.concentrate.ai",
  )
  message = client.messages.create(
      model="claude-sonnet-4-6",
      max_tokens=2048,
      messages=[{"role": "user", "content": "Say hello in one sentence."}],
  )
  print(message.content[0].text)
  ```

  ```javascript JavaScript theme={null}
  import Anthropic from "@anthropic-ai/sdk";

  const client = new Anthropic({
    apiKey: process.env.CONCENTRATE_API_KEY,
    baseURL: "https://api.concentrate.ai",
  });
  const message = await client.messages.create({
    model: "claude-sonnet-4-6",
    max_tokens: 2048,
    messages: [{ role: "user", content: "Say hello in one sentence." }],
  });
  console.log(message.content[0].text);
  ```
</CodeGroup>

The examples below reuse the `client` configured above.

## Stream text

<CodeGroup>
  ```python Python theme={null}
  with client.messages.stream(
      model="claude-sonnet-4-6",
      max_tokens=2048,
      messages=[{"role": "user", "content": "Tell me a short story."}],
  ) as stream:
      for text in stream.text_stream:
          print(text, end="", flush=True)
  ```

  ```javascript JavaScript theme={null}
  const stream = client.messages.stream({
    model: "claude-sonnet-4-6",
    max_tokens: 2048,
    messages: [{ role: "user", content: "Tell me a short story." }],
  });
  stream.on("text", (text) => process.stdout.write(text));
  await stream.finalMessage();
  ```
</CodeGroup>

## Call a function

Define a tool and read the arguments the model returns. Your app runs the function.

<CodeGroup>
  ```python Python theme={null}
  message = client.messages.create(
      model="claude-sonnet-4-6",
      max_tokens=2048,
      messages=[{"role": "user", "content": "Use get_weather for Paris."}],
      tools=[{
          "name": "get_weather",
          "description": "Get weather for a city",
          "input_schema": {
              "type": "object",
              "properties": {"city": {"type": "string"}},
              "required": ["city"],
          },
      }],
      tool_choice={"type": "tool", "name": "get_weather"},
  )
  call = next(block for block in message.content if block.type == "tool_use")
  print(call.input["city"])
  ```

  ```javascript JavaScript theme={null}
  const message = await client.messages.create({
    model: "claude-sonnet-4-6",
    max_tokens: 2048,
    messages: [{ role: "user", content: "Use get_weather for Paris." }],
    tools: [{
      name: "get_weather",
      description: "Get weather for a city",
      input_schema: {
        type: "object",
        properties: { city: { type: "string" } },
        required: ["city"],
      },
    }],
    tool_choice: { type: "tool", name: "get_weather" },
  });
  const call = message.content.find((block) => block.type === "tool_use");
  console.log(call.input.city);
  ```
</CodeGroup>

To continue the conversation, include the assistant's response in the next request, followed by a user message containing a `tool_result` block with `tool_use_id` set to `call.id`. See [Anthropic's tool use guide](https://platform.claude.com/docs/en/agents-and-tools/tool-use/how-tool-use-works).

## Get structured JSON

<CodeGroup>
  ```python Python theme={null}
  import json

  message = client.messages.create(
      model="claude-sonnet-4-6",
      max_tokens=2048,
      messages=[{"role": "user", "content": "Return JSON with status set to ready."}],
      output_config={"format": {
          "type": "json_schema",
          "schema": {
              "type": "object",
              "properties": {"status": {"type": "string"}},
              "required": ["status"],
              "additionalProperties": False,
          },
      }},
  )
  text = "".join(block.text for block in message.content if block.type == "text")
  print(json.loads(text)["status"])
  ```

  ```javascript JavaScript theme={null}
  const message = await client.messages.create({
    model: "claude-sonnet-4-6",
    max_tokens: 2048,
    messages: [{ role: "user", content: "Return JSON with status set to ready." }],
    output_config: { format: {
      type: "json_schema",
      schema: {
        type: "object",
        properties: { status: { type: "string" } },
        required: ["status"],
        additionalProperties: false,
      },
    } },
  });
  const text = message.content
    .filter((block) => block.type === "text")
    .map((block) => block.text)
    .join("");
  console.log(JSON.parse(text).status);
  ```
</CodeGroup>

## Explore more

* Send images with [multimodal input](/docs/api-reference/endpoint/multi-modal).
* Continue a conversation by passing previous user and assistant messages in `messages`.

<Note>
  Use `https://api.concentrate.ai` for the Anthropic SDK base URL. The SDK adds the Messages API path automatically.
</Note>
