Installation
Usage
Context: Add
Version Requirements: The 
groupName field is introduced in Python SDK version 0.5.0. If you use groupName in previous versions, you will encounter an error. If groupName is not provided, it will be set to a default value automatically.groupName: The group name acts like a namespace which creates a scope for context. Documents with the same group name will be grouped together for better organization and retrieval.Example Use Cases:
['project-alpha']- Group all documents related to a specific project['customer-support', 'tier-1']- Organize support documentation by department and priority['legal', 'contracts']- Categorize legal documents by type and category['training', 'onboarding']- Group training materials for new employee onboarding
Context: Search
api_key keyword argument,
we recommend using python-dotenv
to add ALCHEMYST_AI_API_KEY="My API Key" to your .env file
so that your API Key is not stored in source control.
Async usage
Simply importAsyncAlchemystAI instead of AlchemystAI and use await with each API call:
With aiohttp
By default, the async client useshttpx for HTTP requests. However, for improved concurrency performance you may also use aiohttp as the HTTP backend.
You can enable this by installing aiohttp:
http_client=DefaultAioHttpClient():
Using types
Nested request parameters are TypedDicts. Responses are Pydantic models which also provide helper methods for things like:- Serializing back into JSON, 
model.to_json() - Converting to a dictionary, 
model.to_dict() 
python.analysis.typeCheckingMode to basic.
Nested params
Nested parameters are dictionaries, typed usingTypedDict, for example:
Handling errors
When the library is unable to connect to the API (for example, due to network connection problems or a timeout), a subclass ofalchemyst_ai.APIConnectionError is raised.
When the API returns a non-success status code (that is, 4xx or 5xx
response), a subclass of alchemyst_ai.APIStatusError is raised, containing status_code and response properties.
All errors inherit from alchemyst_ai.APIError.
| Status Code | Error Type | 
|---|---|
| 400 | BadRequestError | 
| 401 | AuthenticationError | 
| 403 | PermissionDeniedError | 
| 404 | NotFoundError | 
| 422 | UnprocessableEntityError | 
| 429 | RateLimitError | 
| >=500 | InternalServerError | 
| N/A | APIConnectionError | 
Retries
Certain errors are automatically retried 2 times by default, with a short exponential backoff. Connection errors (for example, due to a network connectivity problem), 408 Request Timeout, 409 Conflict, 429 Rate Limit, and >=500 Internal errors are all retried by default. You can use themax_retries option to configure or disable retry settings:
Timeouts
By default requests time out after 1 minute. You can configure this with atimeout option,
which accepts a float or an httpx.Timeout object:
APITimeoutError is thrown.
Note that requests that time out are retried twice by default.
Advanced
Logging
We use the standard librarylogging module.
You can enable logging by setting the environment variable ALCHEMYST_AI_LOG to info.
debug for more verbose logging.
How to tell whether None means null or missing
In an API response, a field may be explicitly null, or missing entirely; in either case, its value is None in this library. You can differentiate the two cases with .model_fields_set:
Accessing raw response data (e.g. headers)
The “raw” Response object can be accessed by prefixing.with_raw_response. to any HTTP method call, e.g.,
APIResponse object.
The async client returns an AsyncAPIResponse with the same structure, the only difference being awaitable methods for reading the response content.
.with_streaming_response
The above interface eagerly reads the full response body when you make the request, which may not always be what you want.
To stream the response body, use .with_streaming_response instead, which requires a context manager and only reads the response body once you call .read(), .text(), .json(), .iter_bytes(), .iter_text(), .iter_lines() or .parse(). In the async client, these are async methods.
Making custom/undocumented requests
This library is typed for convenient access to the documented API. If you need to access undocumented endpoints, params, or response properties, the library can still be used.Undocumented endpoints
To make requests to undocumented endpoints, you can make requests usingclient.get, client.post, and other
http verbs. Options on the client will be respected (such as retries) when making this request.
Undocumented request params
If you want to explicitly send an extra param, you can do so with theextra_query, extra_body, and extra_headers request
options.
Undocumented response properties
To access undocumented response properties, you can access the extra fields likeresponse.unknown_prop. You
can also get all the extra fields on the Pydantic model as a dict with
response.model_extra.
Configuring the HTTP client
You can directly override the httpx client to customize it for your use case, including:- Support for proxies
 - Custom transports
 - Additional advanced functionality
 
with_options():
Managing HTTP resources
By default the library closes underlying HTTP connections whenever the client is garbage collected. You can manually close the client using the.close() method if desired, or with a context manager that closes when exiting.
Versioning
This package generally follows SemVer conventions, though certain backwards-incompatible changes may be released as minor versions:- Changes that only affect static types, without breaking runtime behavior.
 - Changes to library internals which are technically public but not intended or documented for external use. (Please open a GitHub issue to let us know if you are relying on such internals.)
 - Changes that we do not expect to impact the vast majority of users in practice.
 

