Read as Markdown
curl --request POST \
--url https://api.agentoffice.dev/v1/documents/{doc_id}/markdown \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '
{
"readUid": "<string>"
}
'import requests
url = "https://api.agentoffice.dev/v1/documents/{doc_id}/markdown"
payload = { "readUid": "<string>" }
headers = {
"Authorization": "Bearer <token>",
"Content-Type": "application/json"
}
response = requests.post(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'POST',
headers: {Authorization: 'Bearer <token>', 'Content-Type': 'application/json'},
body: JSON.stringify({readUid: '<string>'})
};
fetch('https://api.agentoffice.dev/v1/documents/{doc_id}/markdown', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://api.agentoffice.dev/v1/documents/{doc_id}/markdown",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => json_encode([
'readUid' => '<string>'
]),
CURLOPT_HTTPHEADER => [
"Authorization: Bearer <token>",
"Content-Type: application/json"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"strings"
"net/http"
"io"
)
func main() {
url := "https://api.agentoffice.dev/v1/documents/{doc_id}/markdown"
payload := strings.NewReader("{\n \"readUid\": \"<string>\"\n}")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("Authorization", "Bearer <token>")
req.Header.Add("Content-Type", "application/json")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}HttpResponse<String> response = Unirest.post("https://api.agentoffice.dev/v1/documents/{doc_id}/markdown")
.header("Authorization", "Bearer <token>")
.header("Content-Type", "application/json")
.body("{\n \"readUid\": \"<string>\"\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.agentoffice.dev/v1/documents/{doc_id}/markdown")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["Authorization"] = 'Bearer <token>'
request["Content-Type"] = 'application/json'
request.body = "{\n \"readUid\": \"<string>\"\n}"
response = http.request(request)
puts response.read_body{
"detail": "Document not found or has expired"
}
{
"detail": "Markdown read operation timed out after 5 minutes"
}
{
"detail": "Failed to generate markdown: Unsupported document format"
}
API Reference
Read as Markdown
Extract document content as markdown for your agent to read
POST
/
v1
/
documents
/
{doc_id}
/
markdown
Read as Markdown
curl --request POST \
--url https://api.agentoffice.dev/v1/documents/{doc_id}/markdown \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '
{
"readUid": "<string>"
}
'import requests
url = "https://api.agentoffice.dev/v1/documents/{doc_id}/markdown"
payload = { "readUid": "<string>" }
headers = {
"Authorization": "Bearer <token>",
"Content-Type": "application/json"
}
response = requests.post(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'POST',
headers: {Authorization: 'Bearer <token>', 'Content-Type': 'application/json'},
body: JSON.stringify({readUid: '<string>'})
};
fetch('https://api.agentoffice.dev/v1/documents/{doc_id}/markdown', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://api.agentoffice.dev/v1/documents/{doc_id}/markdown",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => json_encode([
'readUid' => '<string>'
]),
CURLOPT_HTTPHEADER => [
"Authorization: Bearer <token>",
"Content-Type: application/json"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"strings"
"net/http"
"io"
)
func main() {
url := "https://api.agentoffice.dev/v1/documents/{doc_id}/markdown"
payload := strings.NewReader("{\n \"readUid\": \"<string>\"\n}")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("Authorization", "Bearer <token>")
req.Header.Add("Content-Type", "application/json")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}HttpResponse<String> response = Unirest.post("https://api.agentoffice.dev/v1/documents/{doc_id}/markdown")
.header("Authorization", "Bearer <token>")
.header("Content-Type", "application/json")
.body("{\n \"readUid\": \"<string>\"\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.agentoffice.dev/v1/documents/{doc_id}/markdown")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["Authorization"] = 'Bearer <token>'
request["Content-Type"] = 'application/json'
request.body = "{\n \"readUid\": \"<string>\"\n}"
response = http.request(request)
puts response.read_body{
"detail": "Document not found or has expired"
}
{
"detail": "Markdown read operation timed out after 5 minutes"
}
{
"detail": "Failed to generate markdown: Unsupported document format"
}
Read Document as Markdown
Extract document content as markdown text. Your agent should use this to read documents before editing and verify changes after edits are applied.Path Parameters
string
required
The unique identifier of the document (UUID)
Request Body
string
required
Client-provided UUID for idempotency and tracking. Generate a new UUID for
each read request.
Response
string
required
The UUID of the read operation (same as request)
string
required
Markdown representation of the document content
number
required
Time taken to generate the markdown in seconds
string
required
Name of the document
string
required
UUID of the document
Code Examples
import { v4 as uuidv4 } from "uuid";
const docId = "a1b2c3d4-e5f6-7890-abcd-ef1234567890";
const response = await fetch(
`https://api.agentoffice.dev/v1/documents/${docId}/markdown`,
{
method: "POST",
headers: {
Authorization: "Bearer YOUR_API_KEY",
"Content-Type": "application/json",
},
body: JSON.stringify({
readUid: uuidv4(),
}),
}
);
const data = await response.json();
console.log("Markdown content:");
console.log(data.markdown);
import requests
import uuid
doc_id = 'a1b2c3d4-e5f6-7890-abcd-ef1234567890'
url = f'https://api.agentoffice.dev/v1/documents/{doc_id}/markdown'
headers = {
'Authorization': 'Bearer YOUR_API_KEY',
'Content-Type': 'application/json'
}
payload = {
'readUid': str(uuid.uuid4())
}
response = requests.post(url, headers=headers, json=payload)
data = response.json()
print('Markdown content:')
print(data['markdown'])
print(f"\nGenerated in {data['timeToGenerate']} seconds")
from agent_office import AgentOffice
client = AgentOffice(api_key="YOUR_API_KEY")
doc_id = "a1b2c3d4-e5f6-7890-abcd-ef1234567890"
result = client.read(doc_id=doc_id)
print("Markdown content:")
print(result.markdown)
print(f"\nGenerated in {result.time_to_generate} seconds")
curl -X POST 'https://api.agentoffice.dev/v1/documents/a1b2c3d4-e5f6-7890-abcd-ef1234567890/markdown' \
-H 'Authorization: Bearer YOUR_API_KEY' \
-H 'Content-Type: application/json' \
-d '{
"readUid": "550e8400-e29b-41d4-a716-446655440000"
}'
Example Response
{
"readUid": "550e8400-e29b-41d4-a716-446655440000",
"markdown": "# Q4 Financial Report\n\n## Executive Summary\n\nThis report covers the financial performance for Q4 2024...\n\n## Revenue Analysis\n\n- Total Revenue: $2.5M\n- Growth: 15% YoY\n\n## Conclusion\n\nThe company showed strong performance in Q4.",
"timeToGenerate": 2.1,
"documentName": "report.docx",
"documentId": "a1b2c3d4-e5f6-7890-abcd-ef1234567890"
}
Use Cases
Content Extraction
Extract document content for search indexing or data processing
AI Integration
Feed document content to LLMs for analysis or summarization
Version Control
Track document changes in markdown-friendly version control systems
Web Display
Display document content on websites using markdown renderers
Processing Markdown Content
Here’s how to use the markdown output in different scenarios:import { v4 as uuidv4 } from "uuid";
// Get markdown
const response = await fetch(
`https://api.agentoffice.dev/v1/documents/${docId}/markdown`,
{
method: "POST",
headers: {
Authorization: `Bearer ${API_KEY}`,
"Content-Type": "application/json",
},
body: JSON.stringify({ readUid: uuidv4() }),
}
);
const { markdown } = await response.json();
// Search for specific content
if (markdown.includes("financial report")) {
console.log("Found financial report content");
}
// Extract headers
const headers = markdown.match(/^#{1,6} .+$/gm);
console.log("Document headers:", headers);
from agent_office import AgentOffice
from openai import OpenAI
# Get document as markdown
agent_office = AgentOffice(api_key="YOUR_AGENT_OFFICE_KEY")
result = agent_office.read(doc_id=doc_id)
markdown = result.markdown
# Analyze with OpenAI
openai_client = OpenAI()
completion = openai_client.chat.completions.create(
model="gpt-4",
messages=[
{
"role": "user",
"content": f"Summarize this document:\n\n{markdown}"
}
]
)
print(completion.choices[0].message.content)
import fs from "fs";
import { v4 as uuidv4 } from "uuid";
const response = await fetch(
`https://api.agentoffice.dev/v1/documents/${docId}/markdown`,
{
method: "POST",
headers: {
Authorization: `Bearer ${API_KEY}`,
"Content-Type": "application/json",
},
body: JSON.stringify({ readUid: uuidv4() }),
}
);
const { markdown, documentName } = await response.json();
// Save as .md file
const mdFilename = documentName.replace(/\.[^/.]+$/, ".md");
fs.writeFileSync(mdFilename, markdown);
console.log(`Saved to ${mdFilename}`);
Markdown Formatting
The markdown output preserves document structure including:- Headings: Converted to markdown headers (# ## ###)
- Lists: Bullet points and numbered lists
- Tables: Formatted as markdown tables
- Bold/Italic: Text formatting preserved
- Links: Hyperlinks maintained
- Images: Image references with descriptions (if available)
Example Conversion
- Original Document
- Markdown Output
A Word document with:
- Heading: “Financial Report”
- Bold text: “Q4 Results”
- Table with revenue data
- Bulleted list of achievements
# Financial Report
**Q4 Results**
| Quarter | Revenue | Growth |
| ------- | ------- | ------ |
| Q4 | $2.5M | 15% |
- Exceeded revenue targets
- Expanded to new markets
- Launched 3 new products
Alternative: Get Markdown During Upload
You can also request markdown when uploading a document by settingreturn_markdown=true:
const formData = new FormData();
formData.append("file", file);
formData.append("return_markdown", "true");
const response = await fetch("https://api.agentoffice.dev/v1/documents/", {
method: "POST",
headers: { Authorization: `Bearer ${API_KEY}` },
body: formData,
});
const { docId, markdown } = await response.json();
console.log("Markdown:", markdown);
files = {'file': open('document.docx', 'rb')}
data = {'return_markdown': True}
response = requests.post(
'https://api.agentoffice.dev/v1/documents/',
headers={'Authorization': f'Bearer {API_KEY}'},
files=files,
data=data
)
result = response.json()
print(result['markdown'])
Queue Processing
Like edits, markdown read operations are queued per document to ensure consistency:// Multiple read requests to the same document are processed sequentially
const read1 = fetch(
`https://api.agentoffice.dev/v1/documents/${docId}/markdown`,
{
method: "POST",
headers: {
Authorization: `Bearer ${API_KEY}`,
"Content-Type": "application/json",
},
body: JSON.stringify({ readUid: uuidv4() }),
}
);
const read2 = fetch(
`https://api.agentoffice.dev/v1/documents/${docId}/markdown`,
{
method: "POST",
headers: {
Authorization: `Bearer ${API_KEY}`,
"Content-Type": "application/json",
},
body: JSON.stringify({ readUid: uuidv4() }),
}
);
// Both will complete, processed in order
const [result1, result2] = await Promise.all([read1, read2]);
Error Responses
{
"detail": "Document not found or has expired"
}
{
"detail": "Markdown read operation timed out after 5 minutes"
}
{
"detail": "Failed to generate markdown: Unsupported document format"
}
Markdown generation typically takes 1-5 seconds depending on document
complexity.

