Skip to content
Rigel docs
Open Rigel

Save the text read from a file

documents.document.save_text

POST/api/v1/households/{household_id}/commands/documents.document.save_text

  • Command
  • Rigel runs it
  • Applies offline

Records the text of an uploaded file: a PDF's text layer, or what you read from a scan or photo. Replaces any earlier text and sets how it was read (text_source). Optionally also sets a better title and the summary. Only for documents that are files; refused with document_not_file for Markdown and HTML.

Parameters#

Save the text read from a file: parameters
FieldDescription
household_idpathstringrequired

The household's ID.

Idempotency-Keyheaderstringoptional

The command's ID. Reuse it when retrying the same command.

Request body#

JSON, as application/json.

Save the text read from a file: request body fields
FieldDescription
document_idstringrequired

A document ID, such as doc_01JC0000000000000000000000.

contentstringrequired

The file's text. At most 2,000,000 characters.

text_sourceone of: text_layer, none, rigelrequired

How the text was read: text_layer (a PDF's own text, read without a model), none (read, but there was no text, as in a scan or photo), or rigel (Rigel read it with a model).

titlestringoptional

A better title, when the file name is unhelpful.

1 to 300 characters
summarystringoptional

What the file is and the facts people will look for.

at most 5,000 characters

Response#

200 The command was applied.

Save the text read from a file: response fields
FieldDescription
resultobjectrequired

What the command returned, such as the IDs it created.

result.content_versionintegerrequired

The document's content_version after the change.

versionintegerrequired

The household version after the command.

Errors#

Every error has the same envelope: error.code, error.message, error.details, error.recovery and error.request_id.

Save the text read from a file: errors
StatusCodeWhen
400validation_failedA field is missing, misspelled or out of range. details.fields lists each problem.
401unauthenticatedThe request has no valid session.
404document_not_foundA document that is gone.
404not_foundThe household doesn't exist, or you aren't a member of it.
409document_not_fileA Markdown document.
409idempotency_key_reusedThe Idempotency-Key was already used for a different command.

Examples#

These are real. Each scenario is one of the command's test cases, run on a household when this site was built, and the response is what the API returned.

A PDF's text layer

Request, curl
curl -X POST 'https://rigel.house/api/v1/households/hh_01K9BKKP003AHRZ6DMV29GQY5C/commands/documents.document.save_text' \
  -H "Cookie: rigel_session=$RIGEL_SESSION" \
  -H 'Content-Type: application/json' \
  -H 'Idempotency-Key: cmd_01JC4N0000AAAAAAAAAAAAAAAA' \
  -d '{
  "document_id": "doc_01JC000000000000000000000F",
  "content": "Policy H-2231",
  "text_source": "text_layer"
}'
Request, TypeScript
const response = await fetch("https://rigel.house/api/v1/households/hh_01K9BKKP003AHRZ6DMV29GQY5C/commands/documents.document.save_text", {
  method: "POST",
  headers: {
    "Content-Type": "application/json",
    "Idempotency-Key": "cmd_01JC4N0000AAAAAAAAAAAAAAAA",
    Cookie: `rigel_session=${process.env.RIGEL_SESSION}`,
  },
  body: JSON.stringify({
    document_id: "doc_01JC000000000000000000000F",
    content: "Policy H-2231",
    text_source: "text_layer",
  }),
});
const data = await response.json();
Request, HTTP
POST /api/v1/households/hh_01K9BKKP003AHRZ6DMV29GQY5C/commands/documents.document.save_text HTTP/1.1
Host: rigel.house
Cookie: rigel_session=<your session>
Content-Type: application/json
Idempotency-Key: cmd_01JC4N0000AAAAAAAAAAAAAAAA

{
  "document_id": "doc_01JC000000000000000000000F",
  "content": "Policy H-2231",
  "text_source": "text_layer"
}
Response, 200
HTTP/1.1 200 OK
Content-Type: application/json
X-Request-Id: req_01K9D9S2R0KK8MQ31V60TNHZPV

{
  "result": {
    "content_version": 2
  },
  "version": 1
}

A scan with no text, and a better title and summary

Request, curl
curl -X POST 'https://rigel.house/api/v1/households/hh_01K9BKKP003AHRZ6DMV29GQY5C/commands/documents.document.save_text' \
  -H "Cookie: rigel_session=$RIGEL_SESSION" \
  -H 'Content-Type: application/json' \
  -H 'Idempotency-Key: cmd_01JC4N0000AAAAAAAAAAAAAAAA' \
  -d '{
  "document_id": "doc_01JC000000000000000000000F",
  "content": "",
  "text_source": "none",
  "title": "Car insurance card",
  "summary": "Expires 2027-03-01"
}'
Request, TypeScript
const response = await fetch("https://rigel.house/api/v1/households/hh_01K9BKKP003AHRZ6DMV29GQY5C/commands/documents.document.save_text", {
  method: "POST",
  headers: {
    "Content-Type": "application/json",
    "Idempotency-Key": "cmd_01JC4N0000AAAAAAAAAAAAAAAA",
    Cookie: `rigel_session=${process.env.RIGEL_SESSION}`,
  },
  body: JSON.stringify({
    document_id: "doc_01JC000000000000000000000F",
    content: "",
    text_source: "none",
    title: "Car insurance card",
    summary: "Expires 2027-03-01",
  }),
});
const data = await response.json();
Request, HTTP
POST /api/v1/households/hh_01K9BKKP003AHRZ6DMV29GQY5C/commands/documents.document.save_text HTTP/1.1
Host: rigel.house
Cookie: rigel_session=<your session>
Content-Type: application/json
Idempotency-Key: cmd_01JC4N0000AAAAAAAAAAAAAAAA

{
  "document_id": "doc_01JC000000000000000000000F",
  "content": "",
  "text_source": "none",
  "title": "Car insurance card",
  "summary": "Expires 2027-03-01"
}
Response, 200
HTTP/1.1 200 OK
Content-Type: application/json
X-Request-Id: req_01K9D9S2R0ZQZ8PT7WT46Q72DZ

{
  "result": {
    "content_version": 2
  },
  "version": 1
}

A Markdown document

Request, curl
curl -X POST 'https://rigel.house/api/v1/households/hh_01K9BKKP003AHRZ6DMV29GQY5C/commands/documents.document.save_text' \
  -H "Cookie: rigel_session=$RIGEL_SESSION" \
  -H 'Content-Type: application/json' \
  -H 'Idempotency-Key: cmd_01JC4N0000AAAAAAAAAAAAAAAA' \
  -d '{
  "document_id": "doc_01JC0000000000000000000001",
  "content": "y",
  "text_source": "rigel"
}'
Request, TypeScript
const response = await fetch("https://rigel.house/api/v1/households/hh_01K9BKKP003AHRZ6DMV29GQY5C/commands/documents.document.save_text", {
  method: "POST",
  headers: {
    "Content-Type": "application/json",
    "Idempotency-Key": "cmd_01JC4N0000AAAAAAAAAAAAAAAA",
    Cookie: `rigel_session=${process.env.RIGEL_SESSION}`,
  },
  body: JSON.stringify({
    document_id: "doc_01JC0000000000000000000001",
    content: "y",
    text_source: "rigel",
  }),
});
const data = await response.json();
Request, HTTP
POST /api/v1/households/hh_01K9BKKP003AHRZ6DMV29GQY5C/commands/documents.document.save_text HTTP/1.1
Host: rigel.house
Cookie: rigel_session=<your session>
Content-Type: application/json
Idempotency-Key: cmd_01JC4N0000AAAAAAAAAAAAAAAA

{
  "document_id": "doc_01JC0000000000000000000001",
  "content": "y",
  "text_source": "rigel"
}
Response, 409
HTTP/1.1 409 Conflict
Content-Type: application/json
X-Request-Id: req_01K9D9S2R01WAH3MWCE7AFSVDV

{
  "error": {
    "code": "document_not_file",
    "message": "That document isn't an uploaded file. Use write or edit for its text. No changes were applied.",
    "details": {
      "document_id": "doc_01JC0000000000000000000001"
    },
    "recovery": "Read the current state, then send a command that fits it.",
    "request_id": "req_01K9D9S2R01WAH3MWCE7AFSVDV"
  }
}

A document that is gone

Request, curl
curl -X POST 'https://rigel.house/api/v1/households/hh_01K9BKKP003AHRZ6DMV29GQY5C/commands/documents.document.save_text' \
  -H "Cookie: rigel_session=$RIGEL_SESSION" \
  -H 'Content-Type: application/json' \
  -H 'Idempotency-Key: cmd_01JC4N0000AAAAAAAAAAAAAAAA' \
  -d '{
  "document_id": "doc_01JC0000000000000000000001",
  "content": "y",
  "text_source": "rigel"
}'
Request, TypeScript
const response = await fetch("https://rigel.house/api/v1/households/hh_01K9BKKP003AHRZ6DMV29GQY5C/commands/documents.document.save_text", {
  method: "POST",
  headers: {
    "Content-Type": "application/json",
    "Idempotency-Key": "cmd_01JC4N0000AAAAAAAAAAAAAAAA",
    Cookie: `rigel_session=${process.env.RIGEL_SESSION}`,
  },
  body: JSON.stringify({
    document_id: "doc_01JC0000000000000000000001",
    content: "y",
    text_source: "rigel",
  }),
});
const data = await response.json();
Request, HTTP
POST /api/v1/households/hh_01K9BKKP003AHRZ6DMV29GQY5C/commands/documents.document.save_text HTTP/1.1
Host: rigel.house
Cookie: rigel_session=<your session>
Content-Type: application/json
Idempotency-Key: cmd_01JC4N0000AAAAAAAAAAAAAAAA

{
  "document_id": "doc_01JC0000000000000000000001",
  "content": "y",
  "text_source": "rigel"
}
Response, 404
HTTP/1.1 404 Not Found
Content-Type: application/json
X-Request-Id: req_01K9D9S2R0JKNGNZY8VA9P98S2

{
  "error": {
    "code": "document_not_found",
    "message": "That document isn't there any more. No changes were applied.",
    "details": {
      "document_id": "doc_01JC0000000000000000000001"
    },
    "recovery": "Read the current state, then send a command that fits it.",
    "request_id": "req_01K9D9S2R0JKNGNZY8VA9P98S2"
  }
}

Save the text Rigel read from a photo

So the next question about the photo doesn't need it read again.

Request, curl
curl -X POST 'https://rigel.house/api/v1/households/hh_01M6V9CS6GGVFCY7NAS8ZTQV95/commands/documents.document.save_text' \
  -H "Cookie: rigel_session=$RIGEL_SESSION" \
  -H 'Content-Type: application/json' \
  -H 'Idempotency-Key: cmd_01M6V9CTAEX6W9FTTAXW3E0YVS' \
  -d '{
  "document_id": "doc_01M6V9CTAC5Y4Z9FTG59AEDPTH",
  "content": "The pantry'\''s middle shelf. A bag of flour on the left, then three cans of black beans, a box of orzo and a bottle of olive oil.",
  "text_source": "rigel",
  "summary": "A photo of the pantry'\''s middle shelf."
}'
Request, TypeScript
const response = await fetch("https://rigel.house/api/v1/households/hh_01M6V9CS6GGVFCY7NAS8ZTQV95/commands/documents.document.save_text", {
  method: "POST",
  headers: {
    "Content-Type": "application/json",
    "Idempotency-Key": "cmd_01M6V9CTAEX6W9FTTAXW3E0YVS",
    Cookie: `rigel_session=${process.env.RIGEL_SESSION}`,
  },
  body: JSON.stringify({
    document_id: "doc_01M6V9CTAC5Y4Z9FTG59AEDPTH",
    content: "The pantry's middle shelf. A bag of flour on the left, then three cans of black beans, a box of orzo and a bottle of olive oil.",
    text_source: "rigel",
    summary: "A photo of the pantry's middle shelf.",
  }),
});
const data = await response.json();
Request, HTTP
POST /api/v1/households/hh_01M6V9CS6GGVFCY7NAS8ZTQV95/commands/documents.document.save_text HTTP/1.1
Host: rigel.house
Cookie: rigel_session=<your session>
Content-Type: application/json
Idempotency-Key: cmd_01M6V9CTAEX6W9FTTAXW3E0YVS

{
  "document_id": "doc_01M6V9CTAC5Y4Z9FTG59AEDPTH",
  "content": "The pantry's middle shelf. A bag of flour on the left, then three cans of black beans, a box of orzo and a bottle of olive oil.",
  "text_source": "rigel",
  "summary": "A photo of the pantry's middle shelf."
}
Response, 200
HTTP/1.1 200 OK
Content-Type: application/json
X-Request-Id: req_01M6V9CTAEBTH2BF9CBHVQVT3A

{
  "result": {
    "content_version": 2
  },
  "version": 304
}

For Rigel#

Rigel's tool for this command is documents_document_save_text. Rigel runs this on its own, then says what it did. The agent guide has the rest.

Rigel is in early access, and sign-up is by invitation. Open Rigel