| 1 |
#!/usr/bin/env -S uv run python |
| 2 |
|
| 3 |
# Note: you must have installed `anthropic` with the `vertex` extra |
| 4 |
# e.g. `pip install -U anthropic[vertex]` |
| 5 |
|
| 6 |
import asyncio |
| 7 |
|
| 8 |
from anthropic import AnthropicVertex, AsyncAnthropicVertex |
| 9 |
|
| 10 |
|
| 11 |
def sync_client() -> None: |
| 12 |
print("------ Sync Vertex ------") |
| 13 |
|
| 14 |
client = AnthropicVertex() |
| 15 |
|
| 16 |
message = client.messages.create( |
| 17 |
model="claude-sonnet-5-5", |
| 18 |
max_tokens=100, |
| 19 |
messages=[ |
| 20 |
{ |
| 21 |
"role": "user", |
| 22 |
"content": "Hello!", |
| 23 |
} |
| 24 |
], |
| 25 |
) |
| 26 |
print(message.to_json()) |
| 27 |
|
| 28 |
|
| 29 |
async def async_client() -> None: |
| 30 |
print("------ Async Vertex ------") |
| 31 |
|
| 32 |
client = AsyncAnthropicVertex() |
| 33 |
|
| 34 |
message = await client.messages.create( |
| 35 |
model="claude-sonnet-5-5", |
| 36 |
max_tokens=1024, |
| 37 |
messages=[ |
| 38 |
{ |
| 39 |
"role": "user", |
| 40 |
"content": "Hello!", |
| 41 |
} |
| 42 |
], |
| 43 |
) |
| 44 |
print(message.to_json()) |
| 45 |
|
| 46 |
|
| 47 |
sync_client() |
| 48 |
asyncio.run(async_client()) |