Skip to content

PromptManager

python
from elsai_prompts.prompt_manager import PromptManager

The client for fetching prompts from your elsai Prompt Manager instance. Construct one per process; thread-safe.

Constructor

python
PromptManager(
    api_key: str,
    project_id: str,
    environment: str,
    base_url: str | None = None,
    timeout: int = 20,
)

api_keystr

API key issued by the Prompt Manager. Created in the console (API Keys page). Format elsai_<32 chars>. Must be non-empty; raises ValueError otherwise.

project_idstr

UUID of the project to read prompts from. Must be non-empty; raises ValueError otherwise.

environmentstr

Runtime environment of the calling code (e.g. "development", "testing", "production"). Every fetch checks that the active version has been released to this environment. Must be non-empty; raises ValueError otherwise.

base_urlstr | None (default: None)

On-prem only. Base URL of your on-prem deployment. If None, falls back to the PROMPT_MANAGER_API_URL environment variable. On the SaaS build, this argument is ignored — the URL is hardcoded. On the on-prem build, if neither argument nor env var is set, raises ValueError.

timeoutint (default: 20)

HTTP timeout in seconds per request.

Validation: all four required arguments are checked for non-emptiness at construction time. No network call is made; credentials are validated lazily on the first method call.

Raises: ValueError if any required argument is missing or empty.

Methods

Fetch active version

python
PromptManager.get_active_prompt_version(
    prompt_name: str,
    headers: dict | None = None,
) -> PromptContent

Fetch the active version of the named prompt for the SDK's configured environment.

prompt_namestr — Name of the prompt within the project. Case-sensitive.

headersdict | None (default: None) — Optional HTTP headers to attach to the outgoing request. See Custom headers(.

Returns: PromptContent(

Raises:

ExceptionWhen
PromptNotReleasedInEnvironmentError409 — active version exists, not released to the SDK's env
requests.exceptions.HTTPError404 (key/project/prompt missing, no active version, not a member) or other HTTP error
requests.exceptions.TimeoutRequest exceeded timeout seconds
requests.exceptions.ConnectionErrorNetwork failure
requests.exceptions.RequestExceptionAny other request-layer failure
KeyErrorResponse missing the content field (server-side bug)

Example:

python
pm = PromptManager(
    api_key="elsai_xxx",
    project_id="c8bcaabe-b577-49a4-85da-e37d67652d0c",
    environment="development",
)

prompt = pm.get_active_prompt_version("welcome_email")
print(prompt.kind)              # "f_string"
print(prompt.sha)               # "47be37f69681"
print(prompt.render({"name": "Ada"}))

Per-call environment override

python
PromptManager.get_active_prompt_version_for_environment(
    prompt_name: str,
    environment: str,
    headers: dict | None = None,
) -> PromptContent

Same as get_active_prompt_version but overrides the SDK's configured environment for this call only.

prompt_namestr — Name of the prompt within the project.

environmentstr — The environment to fetch under for this call. Must be non-empty.

headersdict | None (default: None) — Same as get_active_prompt_version.

Returns: PromptContent(

Raises: same as get_active_prompt_version, plus ValueError if environment is empty.

Example:

python
prod_prompt = pm.get_active_prompt_version_for_environment(
    "welcome_email",
    environment="production",
)

See Per-call environment( for use cases.

Instance attributes

AttributeTypeDescription
base_urlstrResolved base URL (constructor arg or env var, right-stripped of trailing /)
api_keystrThe API key
project_idstrThe project ID
environmentstrThe default environment
timeoutintConfigured timeout

Endpoint hit by the SDK

For reference — you should not need to call this directly:

GET {base_url}/prompts/active-prompt-version
    ?api_key={api_key}
    &project_id={project_id}
    &prompt_name={prompt_name}
    &environment={environment}

Response on 200:

json
{
  "prompt_id":     "uuid",
  "prompt_name":   "...",
  "kind":          "instruction | f_string | chat | structured",
  "sha":           "12 hex chars",
  "version_label": "v1.0",
  "content":       { "...kind-specific..." },
  "environments":  ["development"]
}

Response on 409 (PromptNotReleasedInEnvironmentError):

json
{
  "detail": {
    "message": "Active version is not released to the requested environment.",
    "available_environments": ["development", "testing"]
  }
}

Response on 404:

json
{ "detail": "Not found" }

Copyright © 2026 elsai foundry.