Configuration
A client needs a Smarter API key and the url of your Smarter platform. Every argument of
Smarter(...) is optional, because each value is looked up in this order:
the arguments of
Smarter(...),environment variables,
the Smarter CLI’s configuration file,
~/.smarter/config.yaml,the defaults: the
prodenvironment ofplatform.smarter.sh.
from smarter import Smarter
client = Smarter(
api_key="your 64-character Smarter api key",
base_url="https://platform.example.com",
timeout=60,
max_retries=2,
)
API keys
An API key belongs to a user of an account, and the SDK can do whatever that user can do. Create
one in the web console, or with a SmarterAuthToken manifest. See
Authentication. Keep it out of your source code: use an
environment variable or a secret manager.
Environment variables
Variable |
Meaning |
|---|---|
|
The API key. |
|
Your platform’s url, e.g. |
|
|
|
The platform’s root domain, e.g. |
|
Seconds to wait for a response. The default is 60, because a prompt that calls several tools can take tens of seconds. |
|
How many times to retry a request that failed for a transient reason. The default is 2. |
|
|
|
Another path for the CLI’s configuration file. |
Without a base url, the url is derived from the environment, exactly as the CLI derives it:
local is http://localhost:9357, alpha, beta and next are
https://<environment>.<root domain>, and prod is https://<root domain>.
Your own HTTP client
Pass an httpx.Client to send requests through a corporate proxy, with custom TLS settings, or
through a test transport. The SDK never closes a client that you passed in.
import httpx
from smarter import Smarter
client = Smarter(http_client=httpx.Client(proxy="http://proxy.example.com:3128", verify="ca.pem"))
Use a client as a context manager, or call close(), to close its connections:
with Smarter() as client:
print(client.whoami().account.account_number)