1

配置 Key 并跑通首个托管会话

安装 SDK,用官方 tree.py 示例创建 Agents API 会话并观察流式事件。

图文25 分钟

课程目录1 / 2

学习位置仅保存在当前浏览器,有效期 180 天。

01 / 图文教材

图文讲义

with OpenAI() as client: with client.beta.agents.sessions.create( agent={ "model": "gpt-6-astra", "instructions": "Write clean code, run it, and report the actual output.", }, environment={"type": "openai_hosted"}, input="Create tree.py, a Python script that prints a readable tree of the files in the current directory. Run it and show me the output.", stream=True, ) as events: for event in events: print(event.to_json(indent=None), flush=True)

const client = new OpenAI(); const events = await client.beta.agents.sessions.create({ agent: { model: "gpt-6-astra", instructions: "Write clean code, run it, and report the actual output.", }, environment: { type: "openai_hosted" }, input: "Create tree.py, a Python script that prints a readable tree of the files in the current directory. Run it and show me the output.", stream: true, }); try { for await (const event of events) { console.log(JSON.stringify(event)); } } finally { events.controller.abort(); }

本课资料