Create queryable API endpoints by combining datasets and models
Endpoints are the primary interface for querying Syft Space. They combine datasets, models, and policies into a single API that clients can query to retrieve information or generate responses.
class ResponseType(Enum): RAW = "raw" # Dataset search only SUMMARY = "summary" # Model generation only BOTH = "both" # Dataset search + model generation (RAG)
Verify request has valid SyftHub tokenExtract sender_email from token for policy context
2
Pre-hook policies
Execute all attached policies’ pre_hook() methods
for policy_type, configs in policies_by_type.items(): policy_instance.pre_hook(configs, context)
Policies can:
Block request (raise PolicyViolationError)
Modify context/request
Perform authorization checks
3
Dataset search (if configured)
Search dataset with user query:
if response_type in [RAW, BOTH] and dataset_id: result = await dataset.search(ctx, query, params)
Parameters from request:
similarity_threshold
limit
include_metadata
4
Model chat (if configured)
Generate response with optional context injection:
if response_type in [SUMMARY, BOTH] and model_id: # Inject search results as context if references: messages.insert(0, system_context_message) result = await model.chat(ctx, messages, params)
Parameters from request:
temperature
max_tokens
stop_sequences
5
Post-hook policies
Execute all attached policies’ post_hook() methods
for policy_type, configs in policies_by_type.items(): policy_instance.post_hook(configs, context)
Policies can:
Block response (raise PolicyViolationError)
Record accounting transaction
Log usage metrics
6
Return response
Return combined result to clientResponse shape depends on response_type
Endpoints can be published to SyftHub marketplaces:
async def publish_endpoint( slug: str, marketplace_ids: list[UUID] | None, publish_to_all_marketplaces: bool, tenant: Tenant) -> PublishEndpointResponse: """ 1. Validates marketplace exists and is active 2. Authenticates to marketplace with credentials 3. Publishes endpoint metadata via SyftHub API 4. Records publication in endpoint.published_to """
async def sync_endpoints_to_marketplaces( tenant: Tenant) -> dict[str, list[str]]: """ Groups all published endpoints by marketplace Calls sync_endpoints API for each marketplace Returns synced endpoint slugs per marketplace """
async def delete_endpoint(slug: str, tenant: Tenant) -> dict: """ Deletes endpoint and all attached policies. Does NOT delete the linked dataset or model. """