用途:inference.sh 官方 Python SDK,用于在 Python 中运行 AI 应用、构建智能体并接入 150+ 模型。
安装与认证:pip install inferencesh;异步支持用 pip install inferencesh[async];要求 Python 3.8+。通过 inference(api_key="inf_your_key") 初始化,推荐从环境变量 INFERENCE_API_KEY 读取。
运行应用:client.run({"app": "infsh/flux-1-dev", "input": {...}}) 执行应用并返回 status 与 output;wait=False 为异步提交,之后用 client.get_task(id) 查询;stream=True 可流式获取进度。参数含 app、input、setup、infra(cloud/private)、session、session_timeout(1-3600 秒)。
文件与会话:输入中的本地路径可自动上传,也可用 client.upload_file 手动上传并配合 UploadFileOptions 设置文件名、类型与公开性;session="new" 可创建保持热状态的会话,后续调用传入 session_id 复用。
智能体:client.agent("my-team/support-agent@latest") 使用模板智能体,支持 send_message、reset、get_chat;也可用 tool、app_tool、agent_tool、webhook_tool、internal_tools 等构建临时智能体,指定 core_app、system_prompt、tools、temperature、max_tokens。工具参数类型包括 string、number、integer、boolean、enum_of、array、obj、optional。支持流式回调 on_message、on_tool_call,文件附件,以及 skills 复用上下文。
异步与错误:async_inference 提供 await 调用与异步流式;RequirementsNotMetException 可列出缺失要求。支持人工审批工作流。
限制:需 API Key;具体模型、应用与价格以官方为准,资料未提供完整清单与计费细节。