Skip to main content
Some APIs do not answer with the result. They start a job, hand back its id, and the caller asks for the status until the job is done. AWS Textract works this way: StartDocumentAnalysis returns a JobId, and GetDocumentAnalysis reports the status and, once it is done, the pages. Priced as ordinary calls, such an API is charged on every status check, and the price of the work (the pages) is only known at the end. An async job on a route fixes both:
  1. The call that starts the job is charged as usual, with the route’s fee.
  2. Bifrost reads the job id from the reply and checks the job itself, with the relay’s credential, until it reports a final status.
  3. When the job succeeds, Bifrost prices that final reply (for example, pages times a price per page) and charges it once to the budgets the start call was charged to.
  4. The caller’s own status checks cost nothing: Bifrost recognizes a call that matches the job’s status check and relays it free, whatever route it reaches.

Set up a job

  1. Open Relays, select the relay and select Add Async Job above its routes.
  2. Under Start Route (Charged), set the call that starts the job: method POST, path / and the header matcher X-Amz-Target = Textract.StartDocumentAnalysis. Set Fee per Start (USD) to 0.01 and Job ID Path to JobId.
  3. Under Status Check (Free), set how Bifrost checks the job: method POST, path /, the header X-Amz-Target = Textract.GetDocumentAnalysis, the body {"JobId":"{{job.id}}","MaxResults":1} with content type application/x-amz-json-1.1, Status Path JobStatus, Succeeded Statuses SUCCEEDED, PARTIAL_SUCCESS and Failed Statuses FAILED.
  4. Under Job Pricing, set Price per Unit (USD) to 0.0015, Units Read From to the response, Measure to Number at path and Units Path to DocumentMetadata.Pages.
  5. Select Add Async Job.
The job shows in the routes table on its start route. Editing that route opens the async job again.
MaxResults: 1 keeps each check small: Textract still reports JobStatus and DocumentMetadata.Pages, without the full results. The start route names one operation because each start has its own status call: StartDocumentAnalysis is checked with GetDocumentAnalysis, while StartDocumentTextDetection needs GetDocumentTextDetection. To charge text detection jobs too, add a second start route for Textract.StartDocumentTextDetection with its own job.poll.

Fields

A route that starts a job must be billable and is never streamed, because Bifrost reads the job id from its reply.

What is charged

A caller that retries a start and gets the same job id back (Textract does this for a repeated ClientRequestToken) pays the start fee again, but the job is charged only once, also when the retry comes after the job finished. Set reused_id_is_new_job only for an API that reuses ids for new work.
If a gateway node charges a budget and then cannot save that it did, another node can count that one job against the budget a second time. The job’s row in the Relay Logs is still written once.
The final charge goes to the budgets of the virtual key, team and customer that started the job, even if they changed since. It counts no extra request against rate limits.

In Relay Logs

The start call is a row like any other, with its job id and the status started. When the job ends, a job row is added with the final status, the units and the charge. It links to the start call’s row and carries that call’s model, route and the names of its virtual key, user, team and project. A job Bifrost could not price still gets its row, with the reason and a blank cost, and nothing is charged. The job row also shows how the job was followed: how many status checks Bifrost sent (a sweep that skips the job because another node is settling it sends nothing, so it does not count), the last job status it read, the HTTP status of the check that ended it, and when it was settled. The replies to those checks are not stored. A caller’s own status check can settle the job too: when its reply shows the job finished, Bifrost charges the job from that reply at once, as it does for a video retrieve, and the job row names that check. Bifrost’s own polling stays the backstop, and a job is still charged once whichever check finds it finished first.
Jobs are recorded by request logging. With logging off, the start call is still charged its fee, but no job is followed or charged.

Job ids Bifrost will not follow

The job id comes from the API’s reply and goes into the status check’s path. To keep it from reaching another path on the API with the relay’s credential, Bifrost only follows an id of printable characters with no spaces, \, ?, #, . or .. path segments (also with ;params after them, as in ..;x), at most 160 bytes. A reply with any other id is charged as an ordinary call and the job is not followed.