ServiceArchitectClient.from_env().generate_code(project)ServiceArchitectClient and archive API
Low-level reusable API for authenticated generation and validated ZIP handling.
When to use
Use Project.generate_code for one request; use ServiceArchitectClient directly when sharing API-key configuration across requests.
Behavior
- With an API key, the client submits an asynchronous generation job, polls owned status, and follows a short-lived artifact URL.
- The API key is never forwarded to the presigned S3 download URL.
- ID token and Cognito username/password remain a legacy synchronous fallback.
- GeneratedProjectArchive validates ZIP structure before it is returned.
ServiceArchitectClient() properties
Explicit client configuration.
api_keystr | NonePreferred personal Service Architect API key.
Default:Noneid_tokenstr | NoneLegacy existing Cognito ID token.
Default:Noneusername / passwordstr | NoneLegacy Cognito SRP credentials.
Default:Nonebase_urlstr | NoneService Architect API root or environment override.
Default:configured APItimeoutfloatGeneration request timeout in seconds.
Default:120from_env(env_file=".env", **overrides)ServiceArchitectClientLoad standard SERVICE_ARCHITECT_* variables.
generate_code(project)GeneratedProjectArchiveSend the Project and decode the response.
GeneratedProjectArchive properties
Immutable returned artifact.
filenamestrSanSafe filename from Content-Disposition.
contentbytesValidated ZIP bytes.
save(path)PathWrite content and return destination path.
Error classes properties
Structured failure information.
AuthenticationErrorRuntimeErrorCognito rejection, unsupported challenge, invalid SRP values, or connectivity failure; details retains safe response context.
CodeGenerationErrorRuntimeErrorHTTP, API payload, JSON, base64, or ZIP failure; status_code and details are available.
DslValidationErrorValueErrorInvalid object ownership, references, duplicates, or graph operations.
Python example
client = ServiceArchitectClient.from_env()
try:
archive = client.generate_code(project)
archive.save(f"dist/{archive.filename}")
except AuthenticationError as error:
handle_authentication_failure(error)
except CodeGenerationError as error:
handle_generation_failure(error.status_code, error.details)