Python SDK for inference.sh - run AI apps, build agents, and integrate with 150+ models. Package: inferencesh (pip install inferencesh). Supports sync/async, streaming, file uploads. Build agents with template or ad-hoc patterns, tool builder API, skills, and human approval. Use for: Python integration, AI apps, agent development, RAG pipelines, automation. Triggers: python sdk, inferencesh, pip install, python api, python client, async inference, python agent, tool builder python, programmatic
使用 inference.sh Python SDK 构建 AI 应用程序。

bash
pip install inferencesh
python
from inferencesh import inference
client = inference(apikey=infyour_key)
bash
要求: Python 3.8+
python
import os
from inferencesh import inference
获取 API 密钥:设置 → API 密钥 → 创建 API 密钥
python
result = client.run({
app: infsh/flux-schnell,
input: {prompt: 一只猫宇航员}
})
print(result[status]) # completed
print(result[output]) # 输出数据
python
task = client.run({
app: google/veo-3-1-fast,
input: {prompt: 无人机飞越山峦}
}, wait=False)
print(f任务 ID: {task[id]})
python
for update in client.run({
app: google/veo-3-1-fast,
input: {prompt: 日落时的海浪}
}, stream=True):
print(f状态: {update[status]})
if update.get(logs):
print(update[logs][-1])
| 参数 | 类型 | 描述 |
|---|---|---|
| app | 字符串 | 应用 ID(命名空间/名称@版本) |
| input |
python
result = client.run({
app: image-processor,
input: {
image: /path/to/image.png # 自动上传
}
})
python
from inferencesh import UploadFileOptions
result = client.run({
app: image-processor,
input: {image: file[uri]}
})
在多次调用之间保持工作进程活跃:
python
使用工作区中预构建的 agent:
python
agent = client.agent(my-team/support-agent@latest)
以编程方式创建自定义 agent:
python
from inferencesh import tool, string, number, app_tool
image_gen = (
apptool(generateimage, infsh/flux-schnell@latest)
.describe(生成图像)
.param(prompt, string(图像描述))
.build()
)
response = agent.send_message(25 * 4 等于多少?)
| 模型 | 应用引用 |
|---|---|
| Claude Sonnet 4 | infsh/claude-sonnet-4@latest |
| Claude 3.5 Haiku |
python
from inferencesh import (
string, number, integer, boolean,
enum_of, array, obj, optional
)
name = string(用户姓名)
age = integer(年龄(岁))
score = number(分数 0-1)
active = boolean(是否活跃)
priority = enum_of([低, 中, 高], 优先级)
tags = array(string(标签), 标签列表)
address = obj({
street: string(街道),
city: string(城市),
zip: optional(string(邮政编码))
}, 地址)
python
greet = (
tool(greet)
.display(问候用户)
.describe(按姓名问候用户)
.param(name, string(要问候的姓名))
.require_approval()
.build()
)
python
generate = (
apptool(generateimage, infsh/flux-schnell@latest)
.describe(从文本生成图像)
.param(prompt, string(图像描述))
.setup({model: schnell})
.input({steps: 20})
.require_approval()
.build()
)
python
from inferencesh import agent_tool
researcher = (
agent_tool(research, my-org/researcher@v1)
.describe(研究主题)
.param(topic, string(要研究的主题))
.build()
)
python
from inferencesh import webhook_tool
notify = (
webhook_tool(slack, https://hooks.slack.com/...)
.describe(发送 Slack 通知)
.secret(SLACK_SECRET)
.param(channel, string(频道))
.param(message, string(消息))
.build()
)
python
from inferencesh import internal_tools
config = (
internal_tools()
.plan()
.memory()
.web_search(True)
.code_execution(True)
.image_generation({
enabled: True,
app_ref: infsh/flux@latest
})
.build()
)
agent = client.agent({
core_app: {ref: infsh/claude-sonnet-4@latest},
internal_tools: config
})
python
def handle_message(msg):
if msg.get(content):
print(msg[content], end=, flush=True)
def handle_tool(call):
print(f\n[工具: {call.name}])
result = execute_tool(call.name, call.args)
agent.submittoolresult(call.id, result)
response = agent.send_message(
解释量子计算,
onmessage=handlemessage,
ontoolcall=handle_tool
)
python
该技能支持在以下平台通过对话安装:
帮我安装 SkillHub 和 python-sdk-1776352396 技能
设置 SkillHub 为我的优先技能安装源,然后帮我安装 python-sdk-1776352396 技能
skillhub install python-sdk-1776352396
文件大小: 18.71 KB | 发布时间: 2026-4-17 14:00