Skip to content

Context API

Complete reference for the execution context

The context proxy provides access to organization, user, and execution information in workflows and data providers. No need to pass it as a parameter—just import and use it.

from bifrost import workflow, context
@workflow(name="example")
async def example(name: str):
# Access context via proxy - no parameter needed
org_id = context.org_id
user_id = context.user_id
return {"org": org_id, "user": user_id}
PropertyTypeDescriptionExample
user_idstrCurrent user’s ID"user-123"
emailstrUser’s email address"alice@example.com"
namestrUser’s display name"Alice Smith"
PropertyTypeDescriptionExample
org_idstr | NoneOrganization ID"org-456"
org_namestr | NoneOrganization name"Acme Corp"
organizationOrganization | NoneFull organization objectSee Organization type
scopestrScope identifier"org-456" or "GLOBAL"
PropertyTypeDescriptionExample
execution_idstrUnique execution ID"exec-789"
parametersdict[str, Any]Extra parameters passed to workflow{"custom_key": "value"}
startupdict[str, Any] | NoneResults from launch workflow{"user_data": {...}}
PropertyTypeDescription
is_platform_adminboolUser is platform administrator
is_function_keyboolCalled via API key (not user)
is_global_scopeboolExecuting in global scope (no org)
PropertyTypeDescription
roiROIContextROI tracking context
roi.time_savedintMinutes saved (from workflow definition)
roi.valuefloatValue metric (from workflow definition)
MethodParametersReturnsDescription
get_config(key, default=None)key: str, default: AnyAnyAsync method to get config value
# Using get_config method
api_url = await context.get_config("api_url", default="https://api.example.com")

Returns organization ID or None for global scope.

org_id: str | None = context.org_id
if context.org_id:
# Organization-scoped operation
users = await get_org_users(context.org_id)
else:
# Global operation
all_orgs = await get_all_organizations()

Returns organization display name.

org_name: str | None = context.org_name
logger.info(f"Executing for {context.org_name}")

Check if executing in global (platform-wide) scope.

if context.is_global_scope:
# Platform-level operation
pass
else:
# Organization-level operation
pass

When context.organization is not None:

PropertyTypeDescription
idstrOrganization ID
namestrDisplay name
is_activeboolOrganization is active
if context.organization:
org_name = context.organization.name
is_active = context.organization.is_active
from bifrost import workflow, context
@workflow(name="admin_task")
async def admin_task():
if not context.is_platform_admin:
return {
"success": False,
"error": "Admin privileges required"
}
# Perform admin operation
return {"success": True}

Data providers can access context the same way:

from bifrost import data_provider, context
@data_provider(name="get_org_users")
async def get_org_users():
# Filter users by organization
users = await db.query(
"SELECT id, name FROM users WHERE org_id = ?",
context.org_id
)
return [
{"label": u["name"], "value": u["id"]}
for u in users
]
from dataclasses import dataclass
from datetime import datetime
from typing import Any
@dataclass
class ROIContext:
time_saved: int # Minutes saved per execution
value: float # Value metric per execution
@dataclass
class ExecutionContext:
user_id: str
email: str
name: str
scope: str
organization: Organization | None
is_platform_admin: bool
is_function_key: bool
execution_id: str
parameters: dict[str, Any] # Extra parameters passed to workflow
startup: dict[str, Any] | None # Results from launch workflow
roi: ROIContext # ROI tracking context
@property
def org_id(self) -> str | None:
return self.organization.id if self.organization else None
@property
def org_name(self) -> str | None:
return self.organization.name if self.organization else None
@property
def is_global_scope(self) -> bool:
return self.scope == "GLOBAL"
async def get_config(self, key: str, default: Any = None) -> Any:
"""Get a config value for the current scope."""
...
  1. Use the Proxy: Import from bifrost import context - no parameter needed
  2. Always Check org_id: Verify org context before org-scoped operations
  3. Log Context: Include context in log messages for debugging
  4. Don’t Mutate: Context is read-only, don’t try to modify it
  5. Use Properties: Use context.org_id not context.organization.id
  6. Never Log Secrets: Don’t include sensitive data in log messages