Observability Traces Sessions

Sessions

A session groups several related calls together as a single conversation, rather than a set of unrelated rows in the trace list. This is the view to use when a report describes something going wrong over several messages: "it got confused after a few replies," rather than in a single call.

Creating a session

A session is created by reusing the same value in the session key of a call's metadata across every call that belongs to it. There is no separate step to create a session beforehand; sending the same value twice is what groups the two calls together.

  1. Send the first message with a session value

    from forgebench import Forgebench
    
    client = Forgebench(api_key="sk_...", base_url="https://api.forgebench.ai")
    
    client.chat.completions.create(
      model="mock-gpt",
      messages=[{"role": "user", "content": "How do I reset my password?"}],
      extra_body={"metadata": {"dimensions": {"session": "conv_8f21"}}},
    )

    On its own, this call appears in the trace list as usual.

  2. Send the next message with the SAME session value

    Reusing the same client/forgebench from the previous step:

    client.chat.completions.create(
      model="mock-gpt",
      messages=[{"role": "user", "content": "That did not work, now what?"}],
      extra_body={"metadata": {"dimensions": {"session": "conv_8f21"}}},
    )

    Because it carries the same session value as the first, the two are now grouped together as one conversation.

A practical source for this value is whatever your own application already uses to identify a conversation or a ticket, so the two line up without inventing a second identifier.

Reading the sessions view

The session list shows one row per session, with the number of calls it contains and its total cost. Opening a session shows those calls in order, alongside the same totals for the conversation as a whole. This is the figure to use when the question is "what did this conversation cost", rather than adding up individual calls by hand.

A session with one call, then the same session after a second call carrying the same session value

Next

Cookie settings

Our Cookie Policy lists every cookie and what it does.