opper-sdks
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseOpper SDKs
Opper SDKs
The Python and TypeScript SDKs for Opper live in a single monorepo: github.com/opper-ai/opper-sdks. Both publish as (PyPI / npm). Agents are part of the SDK — there is no separate package.
opperaiopperai-agentsThe upstream READMEs (, ) and the numbered example files are the source of truth. This skill points at them; it does not duplicate them.
python/README.mdtypescript/README.mdOpper的Python和TypeScript SDK存放在同一个单体仓库中:github.com/opper-ai/opper-sdks。两者均以的名称发布(分别在PyPI和npm上)。Agent是SDK的一部分——不存在单独的包。
opperaiopperai-agents上游的README文件(、)以及编号示例文件是权威参考来源。本技能仅引导用户查看这些资源,不重复其内容。
python/README.mdtypescript/README.mdPick your primitive
选择合适的基础组件
The unified package exposes a few different shapes. Pick by what you're building:
opperai- One-shot structured task (input → typed output, including image / audio / video generation): is recommended. Pass
opper.call(...)(Python) oroutput_schema=(TS) — Pydantic / Zod / dataclasses / TypedDict / raw JSON Schema all work.outputSchema: - Streaming any of the above: — same shape, async-iterable of typed chunks.
opper.stream(...) - Multi-turn chat or message-thread style: (re-exported from
Conversation) — keeps history acrossopperaiinvocations.opper.call(...) - Tool-using agent, multi-step reasoning, multi-agent, MCP: the Agent SDK (,
Agent,tool,Conversation,Hooks) is recommended for any "model decides what to do next" flow. Usemcpfor a single shot oragent.run(...)for live progress.agent.stream(...) - Drop-in compatibility with OpenAI / Anthropic / Google SDKs: not exposed through the SDK. Recommended: call the compat endpoints directly through the provider's own SDK (point its
opperai/baseURLatbase_url), or see thehttps://api.opper.ai/v3/compatskill for raw HTTP.opper-api - Knowledge bases / RAG: —
opper.knowledge.*,create,query, etc.add
统一的包提供了多种不同的功能形态,可根据你的开发需求选择:
opperai- 一次性结构化任务(输入→类型化输出,包括图像/音频/视频生成):推荐使用****。传入
opper.call(...)(Python)或output_schema=(TypeScript)——Pydantic/Zod/数据类/TypedDict/原生JSON Schema均支持。outputSchema: - 上述任意场景的streaming:——与
opper.stream(...)形态一致,返回类型化分片的异步迭代器。opper.call(...) - 多轮对话或消息线程模式:(从
Conversation重导出)——在多次opperai调用之间保留对话历史。opper.call(...) - 支持工具调用的Agent、多步骤推理、多Agent、MCP:对于任何“由模型决定下一步操作”的流程,推荐使用Agent SDK(、
Agent、tool、Conversation、Hooks)。单次调用使用**mcp,实时进度反馈使用agent.run(...)**。agent.stream(...) - 与OpenAI/Anthropic/Google SDK的即插即用兼容性:未通过SDK暴露。推荐方案:直接通过供应商自身的SDK调用兼容端点(将其
opperai/baseURL指向base_url),或查看**https://api.opper.ai/v3/compat技能**了解原生HTTP调用方式。opper-api - 知识库/RAG:——包含
opper.knowledge.*、create、query等方法。add
Pick a path
选择学习路径
| You are… | Read |
|---|---|
| Writing Python (calls, streaming, schemas, knowledge, tracing) | references/python.md |
| Writing TypeScript / JavaScript | references/typescript.md |
| Building an agent in either language | references/agents.md |
| Calling Opper without an SDK (curl, fetch) | switch to the |
| 你正在开发… | 查看文档 |
|---|---|
| Python(调用、streaming、Schema、知识库、tracing) | references/python.md |
| TypeScript/JavaScript | references/typescript.md |
| 用任意语言构建Agent | references/agents.md |
| 不使用SDK调用Opper(curl、fetch) | 切换至 |
Install
安装
bash
pip install opperai # Python — has one runtime dep: httpx
npm install opperai # TypeScript — zero runtime deps; zod and @modelcontextprotocol/sdk are optional peersAuthentication: both SDKs read from the environment, or accept / in the constructor.
OPPER_API_KEYapi_key=apiKey:bash
pip install opperai # Python — 仅依赖一个运行时库:httpx
npm install opperai # TypeScript — 无运行时依赖;zod和@modelcontextprotocol/sdk为可选对等依赖认证方式:两个SDK均从环境变量读取,或在构造函数中传入/参数。
OPPER_API_KEYapi_key=apiKey:Canonical seed — Python
典型示例 — Python
python
from opperai import Opper
opper = Opper() # uses OPPER_API_KEY
result = opper.call(
"summarise",
instructions="Summarise the article in two sentences.",
input={"text": "..."},
)
print(result.data)python
from opperai import Opper
opper = Opper() # 使用OPPER_API_KEY
result = opper.call(
"summarise",
instructions="Summarise the article in two sentences.",
input={"text": "..."},
)
print(result.data)Canonical seed — TypeScript
典型示例 — TypeScript
ts
import { Opper } from "opperai";
const opper = new Opper(); // uses OPPER_API_KEY
const result = await opper.call("summarise", {
instructions: "Summarise the article in two sentences.",
input: { text: "..." },
});
console.log(result.data);ts
import { Opper } from "opperai";
const opper = new Opper(); // 使用OPPER_API_KEY
const result = await opper.call("summarise", {
instructions: "Summarise the article in two sentences.",
input: { text: "..." },
});
console.log(result.data);The numbered examples are the highest-bandwidth reference
编号示例是最高效的参考资源
Both and hold parallel numbered files. Read by topic.
python/examples/typescript/examples/Getting started ():
examples/getting-started/| Topic | File pattern |
|---|---|
| First call | |
| Schemas — Pydantic / Zod / dataclass / TypedDict / raw JSON Schema | |
| Streaming | |
| Tools — call & stream | |
| Images, audio, video | |
| Embeddings | |
| Function management | |
| Observability / tracing | |
| Models | |
| Real-time | TS-only: |
| Knowledge base | |
| Web tools | |
Agents (, numbered ): first agent → output schema → tools → streaming → hooks (logging / timing / streaming) → agent-as-tool → multi-agent → MCP (stdio) → conversation. See references/agents.md for the topic↔file table.
examples/agents/00..10Type definitions: and .
python/src/opperai/types.pytypescript/src/types.tspython/examples/typescript/examples/入门指南():
examples/getting-started/| 主题 | 文件命名模式 |
|---|---|
| 首次调用 | |
| Schema — Pydantic/Zod/数据类/TypedDict/原生JSON Schema | |
| Streaming | |
| 工具 — 调用与streaming | |
| 图像、音频、视频 | |
| Embeddings | |
| 函数管理 | |
| 可观测性/tracing | |
| 模型 | |
| 实时功能 | TypeScript专属: |
| 知识库 | |
| Web工具 | |
Agent相关(,编号):从第一个Agent→输出Schema→工具→streaming→Hooks(日志/计时/流式传输)→Agent作为工具→多Agent→MCP(标准输入输出)→对话。查看references/agents.md获取主题与文件的对应表。
examples/agents/00..10类型定义:和。
python/src/opperai/types.pytypescript/src/types.tsNon-obvious gotchas
易忽略的注意事项
- No required schema library. Both SDKs accept plain JSON Schema dicts and don't need any third-party schema package. Pydantic (Python) and Zod (TS) are bundled integrations for convenience — most users will reach for them, but they are optional.
- If you use Zod with the TS SDK, it must be v4. . The
npm install zod@4dual-mode package is not supported. (Zod is an optional peer dependency.)zod@3.25.x - Python depends on (not zero-dep at runtime); TypeScript is zero-dep at runtime.
httpx - is the unified package. Old separate
opperai(PyPI) andopperai-agents(npm) are deprecated;@opperai/agents,Agent,tool,Conversation, etc. are all re-exported from the top-levelHooks.opperai - Migration from earlier versions is documented at and
python/MIGRATION.mdupstream.typescript/MIGRATION.md - For API signature questions, fetch the live OpenAPI spec at . The SDK shape mirrors the spec.
https://api.opper.ai/v3/openapi.yaml
- 无强制依赖的Schema库:两个SDK均接受原生JSON Schema字典,无需任何第三方Schema包。Pydantic(Python)和Zod(TypeScript)是为方便用户而集成的可选依赖——大多数用户会选择使用,但它们并非必需。
- 若在TypeScript SDK中使用Zod,必须是v4版本:执行。不支持
npm install zod@4双模式包。(Zod是可选对等依赖。)zod@3.25.x - Python依赖(运行时非零依赖);TypeScript运行时零依赖。
httpx - 是统一包:旧版独立的
opperai(PyPI)和opperai-agents(npm)已被弃用;@opperai/agents、Agent、tool、Conversation等均从顶层Hooks重导出。opperai - 从早期版本迁移的文档位于上游的和
python/MIGRATION.md。typescript/MIGRATION.md - 若有API签名相关问题,可获取实时OpenAPI规范:。SDK的形态与该规范一致。
https://api.opper.ai/v3/openapi.yaml
Where to look next
下一步参考
| For | Look at |
|---|---|
| Install, quick start, full READMEs | opper-sdks repo — |
| Working examples (numbered, progressive) | |
| Type definitions | |
| Live API spec | |
| Migrating from older SDK versions | |
| Repo-level workflows (OpenAPI sync, beta endpoints) | |
| Models available, gateway concepts, raw HTTP | the |
| Calling Opper from a terminal | the |
| 需求 | 查看资源 |
|---|---|
| 安装、快速入门、完整README | opper-sdks仓库 — |
| 可运行示例(编号递进式) | 仓库中的 |
| 类型定义 | |
| 实时API规范 | |
| 从旧版SDK迁移 | |
| 仓库级工作流(OpenAPI同步、Beta端点) | opper-sdks仓库中的 |
| 可用模型、网关概念、原生HTTP调用 | |
| 从终端调用Opper | |