Official Python SDK for the AstarCloud API
Project description
AstarCloud SDK
Python SDK for the AstarCloud API with support for chat completions and tool calling.
Installation
pip install astarcloud-sdk
Quick Start
from AstarCloud import AstarClient
client = AstarClient(api_key="sk-...")
# Basic chat completion
response = client.create.completion(
messages=[{"role": "user", "content": "Hello!"}],
model="gpt-4.1"
)
print(response.choices[0].message.content)
Tool Calling
The SDK supports tool calling for compatible models (gpt-4.1, gpt-4.1-mini, gpt-4.1-nano, astar-gpt-4.1).
Basic Tool Usage
from AstarCloud import AstarClient, ToolSpec
client = AstarClient(api_key="sk-...")
# Define a tool
weather_tool = ToolSpec(
function={
"name": "get_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"
}
},
"required": ["location"]
}
}
)
# Use the tool in a completion
response = client.create.completion(
messages=[{"role": "user", "content": "What's the weather in Paris?"}],
model="gpt-4.1",
tools=[weather_tool],
tool_choice="auto"
)
# Check if the model wants to call a tool
if response.choices[0].tool_calls:
tool_call = response.choices[0].tool_calls[0]
print(f"Tool called: {tool_call.function['name']}")
print(f"Arguments: {tool_call.function['arguments']}")
Bound Tools Client
For convenience, you can create a client with pre-bound tools:
# Create a client with bound tools
bound_client = client.bind_tools([weather_tool])
# All completions will automatically include the bound tools
response = bound_client.create.completion(
messages=[{"role": "user", "content": "What's the weather in Tokyo?"}],
model="gpt-4.1"
)
Streaming
The SDK supports streaming responses:
for chunk in client.create.completion(
messages=[{"role": "user", "content": "Write a story"}],
model="gpt-4.1",
stream=True
):
if chunk.choices[0].message.content:
print(chunk.choices[0].message.content, end="")
Error Handling
from AstarCloud import AstarClient
from AstarCloud._exceptions import APIError, AuthenticationError
try:
response = client.create.completion(
messages=[{"role": "user", "content": "Hello"}],
model="gpt-4.1"
)
except AuthenticationError:
print("Invalid API key")
except APIError as e:
print(f"API error: {e}")
Model Support
Tool-Compatible Models
gpt-4.1gpt-4.1-minigpt-4.1-nanoastar-gpt-4.1
Other models can be used for basic completions but do not support tool calling.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file astarcloud-0.1.5.tar.gz.
File metadata
- Download URL: astarcloud-0.1.5.tar.gz
- Upload date:
- Size: 5.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.11.8
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
4ebe095367511869d71b7d2fc111bcef9657dcdf0c689b7059f3b8f0451154f0
|
|
| MD5 |
b99a57fc7e05ff5042a907ad5c1e157a
|
|
| BLAKE2b-256 |
a08c45f97db5979c1aa4b434caf07de0a7549af2b6f8d62a2a2c75fb460c95a1
|
File details
Details for the file astarcloud-0.1.5-py3-none-any.whl.
File metadata
- Download URL: astarcloud-0.1.5-py3-none-any.whl
- Upload date:
- Size: 6.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.11.8
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
da7ada78f62b6ed953efdb159c2586ae38236bf28b9ce9200947fb1aaf008151
|
|
| MD5 |
10ea51d0afdd685224bc3ae81df2f256
|
|
| BLAKE2b-256 |
75c204254c37557b854ecc64e64f0a075e2b67d57e2f2ed51799a6a66647918e
|