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

# Claude Sonnet 4.6

> Claude Sonnet 4.6 is Anthropic's most capable Sonnet model, delivering the best combination of speed and intelligence in the Claude family.

**Model ID**

```bash theme={null}
anthropic/claude-sonnet-4.6
```

Designed for high-performance applications that require both capability and efficiency, Claude Sonnet 4.6 features much-improved coding skills with better consistency and instruction following. It achieves performance on real-world, economically valuable office tasks that previously required Opus-class models, making it ideal for production workloads where both quality and speed matter.

## API Usage

You can interact with the Anthropic Claude Sonnet 4.6 model through various programming languages and methods. Below are examples showing how to use the model's API.

## API Examples

Generate a model response using the chat endpoint of Anthropic Claude Sonnet 4.6.

### Create chat completion

The Chat Completions API endpoint will generate a model response from a list of messages comprising a conversation.

#### Default

```bash theme={null}
curl https://api.gmi-serving.com/v1/chat/completions \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer $GMI_API_KEY" \
  -d '{
    "model": "anthropic/claude-sonnet-4.6",
    "messages": [
      {
        "role": "system",
        "content": "You are a helpful assistant."
      },
      {
        "role": "user",
        "content": "Hello!"
      }
    ]
  }'
```

#### Streaming

```bash theme={null}
curl https://api.gmi-serving.com/v1/chat/completions \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer $GMI_API_KEY" \
  -d '{
    "model": "anthropic/claude-sonnet-4.6",
    "messages": [
      {
        "role": "system",
        "content": "You are a helpful assistant."
      },
      {
        "role": "user",
        "content": "Hello!"
      }
    ],
    "stream": true
  }'
```

#### Image Input

```bash theme={null}
curl https://api.gmi-serving.com/v1/chat/completions \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer $GMI_API_KEY" \
  -d '{
    "model": "anthropic/claude-sonnet-4.6",
    "messages": [
      {
        "role": "user",
        "content": [
          {
            "type": "text",
            "text": "What is in this image?"
          },
          {
            "type": "image_url",
            "image_url": {
              "url": "https://qianwen-res.oss-cn-beijing.aliyuncs.com/Qwen-VL/assets/demo.jpeg"
            }
          }
        ]
      }
    ],
    "max_completion_tokens": 300
  }'
```

#### Functions

```bash theme={null}
curl https://api.gmi-serving.com/v1/chat/completions \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer $GMI_API_KEY" \
  -d '{
    "model": "anthropic/claude-sonnet-4.6",
    "messages": [
      {
        "role": "user",
        "content": "What is the weather like in Boston today?"
      }
    ],
    "tools": [
      {
        "type": "function",
        "function": {
          "name": "get_current_weather",
          "description": "Get the current weather in a given location",
          "parameters": {
            "type": "object",
            "properties": {
              "location": {
                "type": "string",
                "description": "The city and state, e.g. San Francisco, CA"
              },
              "unit": {
                "type": "string",
                "enum": ["celsius", "fahrenheit"]
              }
            },
            "required": ["location"]
          }
        }
      }
    ],
    "tool_choice": "auto"
  }'
```

#### Python

```python theme={null}
import requests
import json

url = "https://api.gmi-serving.com/v1/chat/completions"
headers = {
    "Content-Type": "application/json",
    "Authorization": "Bearer *************"
}

payload = {
    "model": "anthropic/claude-sonnet-4.6",
    "messages": [
        {"role": "system", "content": "You are a helpful AI assistant"},
        {"role": "user", "content": "List 3 countries and their capitals."}
    ],
    "temperature": 0,
    "max_completion_tokens": 500
}

response = requests.post(url, headers=headers, json=payload)
print(json.dumps(response.json(), indent=2))
```

### Create a message

Anthropic's native Messages API for generating model responses. Supports text and image inputs, and text outputs. Create stateful interactions with the model, using the output of previous responses as input. Extend the model's capabilities with built-in tools for computer use, text editing, and more. Allow the model access to external systems and data using function calling. Enable extended thinking for complex reasoning tasks.

#### Default

```bash theme={null}
curl https://api.gmi-serving.com/v1/messages \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer $GMI_API_KEY" \
  -d '{
    "model": "anthropic/claude-sonnet-4.6",
    "max_tokens": 1024,
    "messages": [
      {"role": "user", "content": "Tell me a three sentence bedtime story about a unicorn."}
    ]
  }'
```

#### Streaming

```bash theme={null}
curl https://api.gmi-serving.com/v1/messages \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer $GMI_API_KEY" \
  -d '{
    "model": "anthropic/claude-sonnet-4.6",
    "max_tokens": 1024,
    "system": "You are a helpful assistant.",
    "messages": [
      {"role": "user", "content": "Hello!"}
    ],
    "stream": true
  }'
```

#### Extended Thinking

```bash theme={null}
curl https://api.gmi-serving.com/v1/messages \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer $GMI_API_KEY" \
  -d '{
    "model": "anthropic/claude-sonnet-4.6",
    "max_tokens": 16000,
    "thinking": {
      "type": "enabled",
      "budget_tokens": 10000
    },
    "messages": [
      {"role": "user", "content": "What is the optimal strategy for solving a complex multi-step math problem?"}
    ]
  }'
```

#### Functions

```bash theme={null}
curl https://api.gmi-serving.com/v1/messages \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer $GMI_API_KEY" \
  -d '{
    "model": "anthropic/claude-sonnet-4.6",
    "max_tokens": 1024,
    "messages": [
      {"role": "user", "content": "What is the weather like in Boston today?"}
    ],
    "tools": [
      {
        "name": "get_current_weather",
        "description": "Get the current weather in a given location",
        "input_schema": {
          "type": "object",
          "properties": {
            "location": {
              "type": "string",
              "description": "The city and state, e.g. San Francisco, CA"
            },
            "unit": {
              "type": "string",
              "description": "Temperature unit",
              "enum": ["celsius", "fahrenheit"]
            }
          },
          "required": ["location"]
        }
      }
    ]
  }'
```

#### Image Input

```bash theme={null}
curl https://api.gmi-serving.com/v1/messages \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer $GMI_API_KEY" \
  -d '{
    "model": "anthropic/claude-sonnet-4.6",
    "max_tokens": 1024,
    "messages": [
      {
        "role": "user",
        "content": [
          {
            "type": "text",
            "text": "What is in this image?"
          },
          {
            "type": "image",
            "source": {
              "type": "url",
              "url": "https://qianwen-res.oss-cn-beijing.aliyuncs.com/Qwen-VL/assets/demo.jpeg"
            }
          }
        ]
      }
    ]
  }'
```

#### PDF Input

```bash theme={null}
curl https://api.gmi-serving.com/v1/messages \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer $GMI_API_KEY" \
  -d '{
    "model": "anthropic/claude-sonnet-4.6",
    "max_tokens": 1024,
    "messages": [
      {
        "role": "user",
        "content": [
          {
            "type": "text",
            "text": "What is in this document?"
          },
          {
            "type": "document",
            "source": {
              "type": "url",
              "url": "https://www.berkshirehathaway.com/letters/2024ltr.pdf"
            }
          }
        ]
      }
    ]
  }'
```

#### Anthropic SDK (Python)

Install the official Anthropic SDK:

```bash theme={null}
pip install anthropic
```

##### Basic Example

```python theme={null}
from anthropic import Anthropic

# Initialize client with custom base URL
client = Anthropic(
    api_key="$GMI_API_KEY", 
    base_url="https://api.gmi-serving.com"
)

# Basic message
message = client.messages.create(
    model="anthropic/claude-sonnet-4.6",
    max_tokens=100,
    messages=[
        {"role": "user", "content": "What is 2+2? Reply with just the number."}
    ]
)
print(message.content[0].text)
print(f"Usage: input={message.usage.input_tokens}, output={message.usage.output_tokens}")
```

##### Streaming Example

```python theme={null}
from anthropic import Anthropic

client = Anthropic(
    api_key="$GMI_API_KEY",
    base_url="https://api.gmi-serving.com"
)

with client.messages.stream(
    model="anthropic/claude-sonnet-4.6",
    max_tokens=100,
    messages=[
        {"role": "user", "content": "Count from 1 to 5."}
    ]
) as stream:
    for text in stream.text_stream:
        print(text, end="", flush=True)
```

## Claude Code

Claude Code is Anthropic's agentic coding tool that lives in your terminal. To use Claude Code with this API endpoint, set the following environment variables before starting Claude Code:

```bash theme={null}
export ANTHROPIC_BASE_URL=https://api.gmi-serving.com
export ANTHROPIC_AUTH_TOKEN=$GMI_API_KEY
export API_TIMEOUT_MS=600000
export CLAUDE_CODE_DISABLE_NONESSENTIAL_TRAFFIC=1
export ANTHROPIC_MODEL="anthropic/claude-sonnet-4.6"
export ANTHROPIC_SMALL_FAST_MODEL="anthropic/claude-sonnet-4.6"
export ANTHROPIC_DEFAULT_SONNET_MODEL="anthropic/claude-sonnet-4.6"
export ANTHROPIC_DEFAULT_OPUS_MODEL="anthropic/claude-opus-4.6"
export ANTHROPIC_DEFAULT_HAIKU_MODEL="anthropic/claude-haiku-4.6"
```

After setting these environment variables, you can launch Claude Code and it will automatically use the configured API endpoint.
