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

Sign up to create a workspace, or log in. Eligible new workspaces receive a $10 grant; see starter-credit eligibility. Add funds in Billing if needed.

Use the owner or admin role to authorize paid work and activate an alternative. Members can save and read drafts.

For the final application call, copy the API key shown on your first dashboard visit, or create one under API keys. Store it securely; the full key is shown only once. Install the Python OpenAI SDK and set these environment variables:

Shell
pip install openai
export SELDON_API_KEY="sk-seldon-..."
export SELDON_BASE_URL="https://api.seldon-ai.com/v1"

Keep your key in your environment or secret manager. The base URL already includes /v1.

Functions are managed in the dashboard. You can prepare and compare a function before changing application traffic; the application calls its alias after you activate it.

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, Lower latency, or Higher task quality.
  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. For your own function, import representative examples and expected answers to evaluate the behavior your application needs. 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.

By default, measurements use synthetic examples. Imported examples can add representative inputs and expected answers. Results describe the evaluation workload, not a guarantee for your production traffic. See How Functions work.

If no worthwhile executable alternative is available, keep your original implementation.

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.

Before switching an existing application, Publish for testing can make the selected immutable revision callable through a pinned alias while the active alias stays unchanged. Rehearse that revision through the application's real parser, then keep the original or activate deliberately.

Targets in a report are descriptive: Met, Missed, Not measured, Not comparable or Insufficient samples. They do not veto activation. Twenty samples is a display minimum, not statistical confidence.

5. Activate

Select a pipeline and choose Activate…. Confirm the tradeoff. If the report shows a warning, acknowledge it before the pipeline is activated. 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