Docs menu

Get started

Optimize your first call

Turn a starter example into an activated Function, compare measured alternatives with the original call, and call the result from your code.

In this tutorial you save a starter example, authorize a preview, run optimization, compare the measured alternatives against your original call, activate one and call it with the OpenAI SDK.

Before you start

  • The owner or admin role in your workspace. Members can save and read drafts; owners and admins authorize paid work and activation.
  • Credits in Billing.
  • An API key and the environment variables from the Quickstart, for the last step.

Functions are managed in the dashboard after you sign in. Your application only uses the public API to call an activated function.

1. Save a starter

  1. In the dashboard, open Functions and choose New function.
  2. On the Examples tab, select Employment extraction. It extracts people, companies and positions from text and returns JSON.
  3. Choose Save draft.

The other starters are Organization linking, a one-call workflow, and Expense policy, a two-call workflow. All three are listed on the public examples page.

2. Prepare the preview

  1. Keep the Compile cap (USD) at 10, or lower it.
  2. Choose a Priority: Lower cost or Lower latency.
  3. Choose Prepare preview.

The preview prepares an evaluation and shows the reference contract: the fixed instructions, the variable input, the output schema and any assumptions. It also shows a quote for the optimization run. Confirm the input boundaries and output schema before you continue. The quote is valid for one hour.

3. Optimize

Choose Optimize. Seldon generates synthetic inputs, searches candidate pipelines and measures each one against your original call, the reference.

The page shows the current stage, elapsed time, the deadline, spending and an estimated finish. Progress survives a reload. Cancel run stops new work; completed usage is still charged.

4. Compare the alternatives

When the run ends, Compare alternatives shows up to three pipelines next to the reference: pass rate, cost per measured execution, p50 and p95 latency, execution failures, refusals and fallback use.

These measurements come from synthetic examples. They describe the evaluation workload, not a guarantee for your production traffic. See How Functions work.

To check a pipeline on your own input, enter it under Try input JSON and choose Try (charges usage), or Compare on this input to run it next to the reference.

5. Activate

Select a pipeline and choose Activate revision. Activation makes it callable. It does not change your application or move any traffic until you call the function.

6. Call it

The function's Use section shows its alias and ready-to-run snippets. For a single-call function, send the original messages with your new input as the last user message, and use the alias as the model:

Python
import os

from openai import OpenAI

client = OpenAI(
    api_key=os.environ["SELDON_API_KEY"],
    base_url=os.environ["SELDON_BASE_URL"],
)

response = client.chat.completions.create(
    model="seldon/function/FUNCTION_ID",
    messages=[
        {"role": "system", "content": "SYSTEM_MESSAGE_FROM_THE_USE_SECTION"},
        {"role": "user", "content": "Grace Ito leads design at Northwind."},
    ],
)
print(response.choices[0].message.content)  # JSON matching the output schema

Copy the system message from the Use section instead of retyping it. Fixed messages must match the saved function exactly.

Next steps

Optimize your first call | Seldon