Functions and Scaling Groups
Find a scaling group's DNS hostname and send requests to it from the SDK.
Every scaling group is automatically assigned a TLS-terminated DNS hostname through the cluster’s gateway. The pattern is:
<environment-id>-<scaling-group-name>.<gateway-domain>
For example, a scaling group named inference in environment abc123 with
gateway domain gw.chalk.ai would be reachable at:
https://abc123-inference.gw.chalk.ai
In the SDK examples on this page, sg is a deployed group, such as the one from
the Quick start. From the SDK, read
the hostname off the deployed group:
print(sg.web_url)
# https://abc123-inference.gw.chalk.ai
From the CLI, the URL is shown as Web URL in the output of chalk scaling-group get and chalk scaling-group list. Traffic arriving at this
hostname is routed to the port you specified with --port (or the port
constructor argument).
Because the hostname includes the scaling group name, you can reference it by a stable, human-readable URL rather than an opaque UUID.
To require a Chalk access token on requests to this hostname, see Authentication.
The .call() helper sends a request to a path under web_url. The response it
returns has status, headers, and content attributes, plus text() and
json() methods. Use .call() for ad-hoc requests from the SDK, and send
production traffic to web_url directly.
This example sends JSON to /predict, which stands for a route your own
service serves:
resp = sg.call(
"/predict",
method="POST",
json={"text": "the cat sat on the mat"},
timeout=60.0,
)
print(resp.json())