获取 API 密钥
概念

超时与中止

大部分电话在60秒后就放弃。 服务器工作几分钟的那些电话故意不这样做,因为放弃这些电话不会停止工作。

60 s defaulttimeout: 0 disablesAbortSignal
Using Python?

Switch any code block to Python: the choice applies to every page. Python SDK guide and resource reference.

默认值

调用截止时间截止时间原因
大部分电话60 秒迄今尚未收到的答复将不来。
models.turn()300 秒转弯可以思考很久 才能找到答案
assistant.generate()无一代人可以花几分钟时间,见下文。
tools.convert(), tools.fetch()无理由是一样的
串流电话无连接是故意开放的。
为什么一代人没有最后期限

工作之所以不停止,是因为您停止了听话:它结束了,电话仍然在账单上。 因此客户端的最后期限会花费您打电话的费用,而不会归还任何信息。 使用中止信号把它打中,而由您控制。

设置您自己的

// For the whole client
const api = new IaGenify({ apiKey, timeout: 15_000 });

// For one call
await api.models.turn({ model, messages, signal: AbortSignal.timeout(30_000) });
# For the whole client, in seconds
api = IaGenify(api_key=api_key, timeout=15)

# For one call
api.models.turn(model=model, messages=messages, timeout=30)

中止中中止

每一个电话都需 signal。您要求的堕胎会按原样通过,不会被重新包装为超时,这样除了客户放弃外,您还可以告诉自己取消。

const controller = new AbortController();

const running = agent.run({
  message: "Audit the whole workspace.",
  onEvent: console.log,
  signal: controller.signal,
});

setTimeout(() => controller.abort(new Error("user cancelled")), 10_000);

try {
  await running;
} catch (err) {
  if (controller.signal.aborted) console.log("cancelled by us");
  else if (err.code === "timeout") console.log("the client gave up");
}
import threading
from iagenify import RequestTimeout

# Python has no AbortSignal: stop the agent from another thread
timer = threading.Timer(10, agent.stop)
timer.start()

try:
    result = agent.run(message="Audit the whole workspace.", on_event=print)
    if result["stopReason"] == "stopped":
        print("cancelled by us")
except RequestTimeout:
    print("the client gave up")
finally:
    timer.cancel()

你将看到两个失败

代码代码代码状态状态状态状态状态状态状态含义
超时超时408截止日期前没有答复。
无法到达503请求从未到过那里: 错误的基调Url, 没有网络, 什么都没有听。

unreachable 几乎总是意味着 baseUrl 不是您指的是的。 读 api.baseUrl 并且比较它, https://api.iagenify.com.