> ## Documentation Index
> Fetch the complete documentation index at: https://docs.vessl.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# Fetch output of an asynchronous request

# Overview

Fetch the status and output of an asynchronous request
(that was created in [request creation API](create-async-request)).

The response will be considered as success or failure depending on its status code.
All status codes between `200` and `299` will be considered as a successful request and display
status `"completed"`; other status codes, especially `400`-`499` (cilent errors) and `500`-`599`
(server errors) will be handled as status `"failed"`.

## Interaction code example

<CodeGroup>
  ```shell curl theme={null}
  $ curl \
      -H "Authorization: Bearer ${TOKEN}" \
      "${BASE_URL}/async/${REQUEST_ID}/output" | jq

  {
      "status": "completed",
      "status_code": 200,
      "raw_output": "{\"text\": \"Hello!\"}",
      "output": {
          "text": "Hello!"
      }
  }
  ```

  ```python Python theme={null}
  import requests
  base_url = "https://..."
  token = "..."
  request_id = "98nlux8b0eu6"

  r = requests.get(
      f"{base_url}/async/{request_id}/output",
      headers={"Authorization": f"Bearer {token}"}
  )
  print(r.json())
  # prints:
  #     {'status': 'completed', 'status_code': 200, 'raw_output': '{"text": "Hello!"}', 'output': {'text': 'Hello!'}}
  ```
</CodeGroup>

# Request

<Info>
  <h3>Authorization</h3>

  You must provide a token in `Authorization` header with `Bearer` scheme, as:

  ```
  Authorization: Bearer <token>
  ```

  The token can be found in the web UI (in service overview's Request dialog).
</Info>

## Path parameters

<ParamField path="base_url" type="string" required>
  Base URL for your service. This value can be found in the web UI (in service overview's
  Request dialog).

  Typical value: `https://serve-api.dev2.vssl.ai/api/v1/services/<slug>`
</ParamField>

<ParamField path="request_id" type="string" required>
  Request ID from [request creation API](create-async-request).

  Example: `98nlux8b0eu6`
</ParamField>

# Response

<ResponseField name="status" type="string">
  Status of the request. Its possible values and meanings are as follows.

  * `"pending"`: The request is waiting in the queue.
  * `"in_progress"`: The request is being processed.
  * `"completed"`: The request has ended with status code `200`-`299`.
  * `"failed"`: The request has ended with status code other than `200`-`299`,
    or an internal error has occurred. In either case, `fail_reason`
    field will also be present.
</ResponseField>

<ResponseField name="status_code" type="int">
  Status code response.

  This field is only present when `status` is either `"completed"` or `"failed"`.
</ResponseField>

<ResponseField name="raw_output" type="string">
  Raw bytes of the response body.

  This field is only present when `status` is either `"completed"` or `"failed"`.
</ResponseField>

<ResponseField name="output" type="any">
  Response body, decoded as JSON. If the response body is not a valid JSON, this field
  is omitted.

  This field is only present when `status` is either `"completed"` or `"failed"`.
</ResponseField>

<ResponseField name="fail_reason" type="string">
  Human-readable explanation for failure.

  This field is only present when `status` is `"failed"`.
</ResponseField>

<ResponseExample>
  ```json Completed theme={null}
  {
      "status": "completed",
      "status_code": 200,
      "raw_output": "{\"text\": \"Hello!\"}",
      "output": {
          "text": "Hello!"
      }
  }
  ```

  ```json Failed theme={null}
  {
      "status": "failed",
      "status_code": 400,
      "raw_output": "{\"message\":\"Request body must contain field 'data'.\"}",
      "output": {
          "message": "Request body must contain field 'data'."
      },
      "fail_reason": "Server responded with status code 400"
  }
  ```

  ```json Pending theme={null}
  {
      "status": "pending"
  }
  ```
</ResponseExample>
