Recipe

Run An Agent Task

Running an agent task with ReqRun means giving the model call an rr_ request id and reading the result when it is ready.

Problem

An agent task may outlive the HTTP request or job that started it.

Code

Start the request asynchronously and store the rr_ id with your own task record.

TypeScript
const response = await reqrun.chat.completions.create({
  model: "gpt-5-nano",
  messages: [{ role: "user", content: "Run the agent task." }],
  wait: false,
  idempotency_key: "agent-task-991",
});

if (response.object === "chat.completion.async") {
  const request = await reqrun.requests.get(response.id);
  console.log(request.status, request.attempts);
}