Skip to main content

synth_ai.sdk.optimization.policy.gepa_online_session

GEPA online session SDK wrapper. This module provides the GepaOnlineSession class for managing online GEPA optimization sessions. In online mode, you drive rollouts locally while the backend proposes new instruction candidates and serves them via a proxy URL. Online GEPA workflow:
  1. Create a session with your GEPA configuration (prompt_learning.gepa.mode=online)
  2. Get proxy URLs for prompt selection
  3. Run rollouts locally, calling the proxy URL for each LLM call
  4. Report rewards back to the session
  5. Backend proposes new prompt candidates based on rewards
Example:
from synth_ai.sdk.optimization.policy import GepaOnlineSession

session = GepaOnlineSession.create(
    backend_url="http://localhost:8000",
    api_key=os.environ["SYNTH_API_KEY"],
    config_body={
        "prompt_learning": {
            "algorithm": "gepa",
            "gepa": {"mode": "online", "online_proposer_min_rollouts": 10},
            "initial_prompt": {"messages": [{"role": "system", "pattern": "You are a classifier..."}]},
        }
    },
)

proxy_url = session.chat_completions_url or session.proxy_url

Classes

GepaOnlineSession

Client wrapper for online GEPA optimization sessions. Key methods:
  • create() / create_async() to start a new session
  • get_status() to fetch live candidate stats
  • get_prompt_urls() to retrieve proxy URLs
  • update_reward() to report per-rollout rewards
  • pause() / resume() / cancel() for lifecycle control