Skip to content
For the complete documentation index, see llms.txt. Markdown versions of documentation pages are available by appending .md to the page URL.
Primary navigation

Create an agent session

client.Beta.Agents.Sessions.New(ctx, body) (*AgentSession, error)
POST/agents/sessions

Creates a managed agent session, optionally submits initial input, and returns the session or streams its events when stream is true. See running sessions.

ParametersExpand Collapse
body BetaAgentSessionNewParams
Environment param.Field[EnvironmentParamUnionResp]

An inline execution environment or a reference to an environment template.

Agent param.Field[BetaAgentSessionNewParamsAgent]Optional

Agent configuration. With agent_id, supplied fields override the saved agent for this session. Without agent_id, model is required.

AgentID param.Field[string]Optional

The ID of a saved reusable agent. Omit agent to use its configuration unchanged.

minLength0
maxLength64
Input param.Field[BetaAgentSessionNewParamsInputUnion]Optional

Initial input to submit when the session is created. A string is shorthand for a single user message. Required when environment.type is none, or when stream is true for an environment that is not self_hosted; optional for self-hosted and non-streaming execution environments.

Metadata param.Field[map[string, string]]Optional

Up to 16 string key-value pairs, with keys up to 64 and values up to 512 characters. Omission or null defaults to an empty map.

SpendControl param.Field[BetaAgentSessionNewParamsSpendControl]Optional

Optional spending limit in USD cents. Omission or null creates an unlimited session.

VaultIDs param.Field[[]string]Optional

The IDs of vaults made available to the session.

ReturnsExpand Collapse
type AgentSession struct{…}

A Managed Agents session.

ID string

The ID of the session.

minLength0
Agent AgentSessionAgent

The agent running in the session.

CreatedAt int64

The Unix timestamp, in seconds, when the session was created.

formatint64
Environment EnvironmentUnion

The execution environment for the session.

Error string

The error that caused the session to fail, if any.

minLength0
LastActiveAt int64

The Unix timestamp, in seconds, when the session was last active.

formatint64
Metadata map[string, string]

Custom string key-value pairs attached to the session.

Object AgentSession

The object type. Always agent.session.

RequiredActions []AgentSessionRequiredActionUnion

Actions that must be completed before the session can continue.

Status AgentSessionStatus

The current status of the session.

Best-effort token usage for the session, or null if unknown. Recorded usage may change.

VaultIDs []string

The IDs of vaults made available to the session.

SpendControl AgentSessionSpendControlOptional

Configured spending limit and best-effort consumption, in USD cents. Unlimited sessions omit this object.

Create an agent session

package main

import (
  "context"
  "fmt"

  "github.com/openai/openai-go"
  "github.com/openai/openai-go/option"
)

func main() {
  client := openai.NewClient(
    option.WithAPIKey("My API Key"),
  )
  agentSession, err := client.Beta.Agents.Sessions.New(context.TODO(), openai.BetaAgentSessionNewParams{
    Environment: openai.EnvironmentParamUnion{
      OfNone: &openai.EnvironmentParamNone{

      },
    },
  })
  if err != nil {
    panic(err.Error())
  }
  fmt.Printf("%+v\n", agentSession.ID)
}
{
  "id": "id",
  "agent": {
    "id": "id",
    "instructions": "instructions",
    "model": "model",
    "multi_agent": {
      "enabled": true,
      "max_concurrent_subagents": 1
    },
    "name": "name",
    "reasoning": {
      "effort": "none",
      "summary": "concise"
    },
    "service_tier": "auto",
    "text": {
      "format": {
        "type": "text"
      },
      "verbosity": "low"
    },
    "tools": [
      {
        "defer_loading": true,
        "description": "description",
        "name": "name",
        "parameters": {
          "foo": "bar"
        },
        "type": "function"
      }
    ]
  },
  "created_at": 0,
  "environment": {
    "type": "none"
  },
  "error": "error",
  "last_active_at": 0,
  "metadata": {
    "foo": "string"
  },
  "object": "agent.session",
  "required_actions": [
    {
      "request": {
        "credential_origin": "credential_origin",
        "fields": [
          {
            "id": "id",
            "label": "label",
            "required": true,
            "type": "type"
          }
        ],
        "options": [
          {
            "id": "id",
            "field_ids": [
              "string"
            ],
            "label": "label"
          }
        ],
        "reason": "reason",
        "type": "browser_authentication"
      },
      "request_id": "request_id",
      "turn_id": "turn_id",
      "type": "computer_use_approval_request"
    }
  ],
  "status": "idle",
  "usage": {
    "input_tokens": 0,
    "input_tokens_details": {
      "cached_tokens": 0
    },
    "output_tokens": 0,
    "output_tokens_details": {
      "reasoning_tokens": 0
    },
    "total_tokens": 0
  },
  "vault_ids": [
    "string"
  ],
  "spend_control": {
    "consumed": 0,
    "limit": 1
  }
}
Returns Examples
{
  "id": "id",
  "agent": {
    "id": "id",
    "instructions": "instructions",
    "model": "model",
    "multi_agent": {
      "enabled": true,
      "max_concurrent_subagents": 1
    },
    "name": "name",
    "reasoning": {
      "effort": "none",
      "summary": "concise"
    },
    "service_tier": "auto",
    "text": {
      "format": {
        "type": "text"
      },
      "verbosity": "low"
    },
    "tools": [
      {
        "defer_loading": true,
        "description": "description",
        "name": "name",
        "parameters": {
          "foo": "bar"
        },
        "type": "function"
      }
    ]
  },
  "created_at": 0,
  "environment": {
    "type": "none"
  },
  "error": "error",
  "last_active_at": 0,
  "metadata": {
    "foo": "string"
  },
  "object": "agent.session",
  "required_actions": [
    {
      "request": {
        "credential_origin": "credential_origin",
        "fields": [
          {
            "id": "id",
            "label": "label",
            "required": true,
            "type": "type"
          }
        ],
        "options": [
          {
            "id": "id",
            "field_ids": [
              "string"
            ],
            "label": "label"
          }
        ],
        "reason": "reason",
        "type": "browser_authentication"
      },
      "request_id": "request_id",
      "turn_id": "turn_id",
      "type": "computer_use_approval_request"
    }
  ],
  "status": "idle",
  "usage": {
    "input_tokens": 0,
    "input_tokens_details": {
      "cached_tokens": 0
    },
    "output_tokens": 0,
    "output_tokens_details": {
      "reasoning_tokens": 0
    },
    "total_tokens": 0
  },
  "vault_ids": [
    "string"
  ],
  "spend_control": {
    "consumed": 0,
    "limit": 1
  }
}