SAService Architect Back to designer
SAService ArchitectDocumentation
Python API reference 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.

PropertyTypeDescription
api_keystr | None

Preferred personal Service Architect API key.

Default: None
id_tokenstr | None

Legacy existing Cognito ID token.

Default: None
username / passwordstr | None

Legacy Cognito SRP credentials.

Default: None
base_urlstr | None

Service Architect API root or environment override.

Default: configured API
timeoutfloat

Generation request timeout in seconds.

Default: 120
from_env(env_file=".env", **overrides)ServiceArchitectClient

Load standard SERVICE_ARCHITECT_* variables.

generate_code(project)GeneratedProjectArchive

Send the Project and decode the response.

GeneratedProjectArchive properties

Immutable returned artifact.

PropertyTypeDescription
filenamestr

SanSafe filename from Content-Disposition.

contentbytes

Validated ZIP bytes.

save(path)Path

Write content and return destination path.

Error classes properties

Structured failure information.

PropertyTypeDescription
AuthenticationErrorRuntimeError

Cognito rejection, unsupported challenge, invalid SRP values, or connectivity failure; details retains safe response context.

CodeGenerationErrorRuntimeError

HTTP, API payload, JSON, base64, or ZIP failure; status_code and details are available.

DslValidationErrorValueError

Invalid 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)