integration

What adopting Second Moment looks like

You don't port your agent to Second Moment. Your code keeps running wherever it runs today. You declare its envelope, a small spec that bounds what a unit of work may spend, and route model calls through Second Moment's gateway. The spec is what makes a fixed price writable and the worst-case cost computable before a single run.

The lifecycle

1
Free quote: zero integration (available today)

Export traces from your provider console or observability stack (Langfuse, LangSmith, Helicone, OTel). Any CSV/JSONL with a per-unit cost or tokens + a unit id works. The pricing demo accepts the same formats.

# what we need, nothing elsetask_id,cost_usd,timestamptkt_1041,0.38,2026-08-02T14:11:09Ztkt_1042,1.94,2026-08-02T14:12:31Z
2
The canary: gateway on a slice, nothing at risk (pilot stage)

Point staging, or a small slice of production, at the gateway with billing at pass-through: you pay actual cost, exactly as today, while Second Moment observes the real thing on the wire (calls, tool round-trips, terminal states) and quotes against it live. The canary also drafts your spec for you: after a week of traffic, Second Moment emits the envelope your agent already operates in (observed steps, model mix, iteration counts, token budgets, terminal states) as a draft spec. You tighten the bounds and sign off. You never start from a blank file. Not convinced? Revert one line and nothing else has changed.

# staging first, or a slice of production, billed at pass-through:client = OpenAI(base_url="https://gw.secondmoment.co/v1")   # illustrative # the whole rollback plan: change this line back
3
Declare the workflow: mapping your loop to a spec

First, what the spec is not: it is not a program, and nothing executes it. Your workflow stays your code. The spec is a policy the gateway enforces against your traffic. Think firewall rules or rate limits, not an orchestrator. Phase names like triage and respond are just labels your calls carry (like span names in tracing), so the meter knows which limit each call counts against. Real agents are loops: a model call, some tool calls, repeat until done. The spec simply names the phases of the loop you already have and puts a number on each:

# your code today (LangGraph / custom loop)      # what the spec declaresstate = triage(ticket)                            → phase "triage": 1 call, budget tierwhile not done:                                   → phase "respond":    reply = llm(ctx, tools=[kb, orders])              each turn = 1 iteration    done  = resolved or escalated or turns > N        max_iterations caps Nclose(ticket, state)                              → terminal: resolved|escalated|abandoned

The minimal valid spec is one phase with an iteration cap and terminal states. That alone makes the worst case computable. Adding phases and tool budgets tightens the envelope, and a tighter envelope is a lower ceiling, reducing your cost. Granularity is a price lever to reduce both variance and expectation. One spec per workflow family, in your repo:

# A support bot (Intercom-style): triage, then a conversational# tool-using loop until the ticket closes. Each agent turn in your# existing loop = one iteration of the `respond` phase.workflow: support-botarchetype: ticket-resolutionunit: ticketsteps:  triage:                        # 1 cheap call: route + severity    model_tier: budget    max_iterations: 1  respond:                       # your agent loop lives here    model_tier: frontier    max_iterations: 12           # turns before forced escalation    tools:      kb_search:    {tool_budget_tokens: 20000}      order_lookup: {tool_budget_tokens: 4000}terminal: [resolved, escalated, abandoned]
# A coding agent (SWE-agent / OpenHands-style): localize the fault,# then an edit->run-tests loop until green or out of budget.workflow: issue-fixerarchetype: code-tasksunit: issuesteps:  localize:    model_tier: budget    max_iterations: 4            # repo search + file reads    tools:      code_search: {tool_budget_tokens: 30000}  fix:    model_tier: frontier    max_iterations: 20           # each edit->test cycle = 1 iteration    tools:      run_tests: {tool_budget_tokens: 15000}terminal: [tests_pass, tests_fail, timeout]
# A research agent (GAIA-style): plan once, a bounded# search-and-read loop, then one synthesis pass.workflow: research-briefarchetype: deep-researchunit: briefsteps:  plan:    model_tier: frontier    max_iterations: 1  gather:    model_tier: budget    max_iterations: 25           # each search-or-read action = 1 iteration    tools:      web_search: {tool_budget_tokens: 8000}      fetch_page: {tool_budget_tokens: 60000}  synthesize:    model_tier: frontier    max_iterations: 2terminal: [delivered, insufficient_sources, timeout]
# A cross-app operator (AppWorld-style RPA successor): plan, act# across SaaS APIs, verify the end state.workflow: ops-runnerarchetype: app-operationunit: tasksteps:  plan:    model_tier: frontier    max_iterations: 2  act:    model_tier: budget    max_iterations: 30           # each API action = 1 iteration    tools:      calendar_api: {tool_budget_tokens: 3000}      email_api:    {tool_budget_tokens: 6000}      crm_api:      {tool_budget_tokens: 6000}  verify:    model_tier: budget    max_iterations: 2terminal: [completed, partial, failed]
# A document pipeline: parse, extract to schema, validate with# bounded retries. Nearly deterministic: the tightest bound and# the cheapest fixed price in the registry.workflow: doc-intakearchetype: document-pipelinesunit: documentsteps:  parse:    tool: ocr_parse    tool_budget_tokens: 50000  extract:    model_tier: budget    max_iterations: 2  validate:    model_tier: budget    max_iterations: 2            # schema-check retriesterminal: [extracted, quarantined]

Submit it and Second Moment answers with the two numbers that define the contract. First the static bound: the worst a single unit can possibly cost, computed from the spec alone before anything runs. Every receipt carries it, and the gateway enforces it. Then, after a burn-in on your real sample inputs, the quote:

$ sm workflows push support-bot.sm.yaml  ✓ wf_7f3a · static bound $3.40/unit · status: needs burn-in $ sm burnin run wf_7f3a samples.jsonl        # 100–200 real inputs, a few $ of tokens  ✓ 184 units · mean $0.86 · p99 $2.20  → quote: $0.95/unit fixed   ·   cap $1.20/unit for $0.06

No history yet? The pre-launch quote. A brand-new feature can be quoted before its first run. The spec alone gives the worst case, and the archetype prior (what workloads of this shape cost across our reference data) gives an indicative band. A band is not a signature, but a band plus an enforced ceiling is enough to set your own customer price with a known cost floor before launch. Ship the feature at pass-through or under a cap on day one. The band hardens into a fixed quote as real units accrue, and beta or design-partner traffic through the gateway counts toward it. New features never wait on us to ship.

$ sm quote wf_7f3a                 # zero runs: spec + archetype prior  → indicative band $0.70–1.30/unit (prior-weighted, credibility Z≈0)  → ceiling $3.40/unit, enforced from the first call  → firm quote at ~150 live units; burn-in and beta traffic count
4
Run: your code, our gateway, close each unit

Your agent executes exactly as before. Two headers tie every model call to its workflow and unit, and the gateway enforces the spec (tier substitution, iteration caps, the hard ceiling) below anything your agent's logic can influence. When a unit finishes, your code declares the terminal state, which closes the unit and fixes what you're billed.

client = OpenAI(    base_url="https://gw.secondmoment.co/v1",           # illustrative    default_headers={        "x-sm-workflow": "wf_7f3a",        "x-sm-unit": ticket.id,                    # your id, any string        "x-sm-step": "resolve"})                   # optional per-step tag # ... your existing agent loop, unchanged ... sm.close(unit=ticket.id, state="resolved")         # or POST /v1/units/{id}/close# unclosed units resolve by declared timeout rules; nothing hangs open

And here is the same unit from the gateway's side: the spec doing its only job, counting and enforcing per label. Note the refusal is not a crash: it's a signal your loop's existing give-up path handles, exactly like any tool error:

# gateway's view of unit tkt_1042 (spec wf_7f3a)call 1   step=triage    iter 1/1  · tier budget ✓   → forwardedcall 2   step=respond   iter 1/12 · tier frontier ✓ → forwarded  (substituted: sonnet-tier)  ⋮call 13  step=respond   iter 12/12                  → forwardedcall 14  step=respond   iter 13/12 · exceeds cap    → REFUSED (429 sm_cap_exceeded)your code catches it    → sm.close(unit, state="escalated")receipt issued          · consumed $0.33 of the $3.40 bound

Untagged calls all count against a single default phase, the minimal spec. Labels can't be gamed into free compute: whatever the labeling, total spend per unit is capped by the static bound, which is what your fixed price was written against.

5
Every unit closes with a priced, auditable receipt

What ran, what it cost at the prices in force at call time, what you were billed, and how much headroom was left under the bound. Receipts are the audit trail behind every invoice and every renewal, including the units Second Moment loses money on.

{  "unit": "tkt_1042",  "workflow": "wf_7f3a",  "terminal_state": "resolved",  "billed": {"fixed_price": 0.95, "tier": "M"},  "execution": {    "calls": 14, "input_tokens": 61240, "output_tokens": 3891,    "cost_at_call_time": 1.12, "model_tiers_used": ["budget", "frontier"],    "ceiling": {"static_bound": 3.40, "consumed": 0.33}  },  "sm_margin_this_unit": -0.17}

Work that can't be given an envelope (unbounded loops, undeclared terminal states) isn't mispriced. It's declined, or covered by a spend ceiling instead of a per-unit price. That refusal is what makes the prices above writable.

The questions a careful engineer asks next (endpoint swap, keys, downtime, context, latency) have moved to the FAQ, alongside the pricing and launch questions buyers ask.