@ailang/parse
JavaScript/TypeScript client and MCP server for the AILANG Parse document parsing API. Parse 19 formats (including LaTeX/arXiv and RTF), generate 9 — zero dependencies, native fetch.
Install
npm install @ailang/parse
MCP Server (Claude Desktop, Cursor, VS Code)
Run as a stdio MCP server that bridges to the hosted AILANG Parse API. Requires Node.js >= 18.
{
"mcpServers": {
"ailang-parse": {
"command": "npx",
"args": ["-y", "@ailang/parse", "mcp"]
}
}
}
Add to claude_desktop_config.json (Claude Desktop), .cursor/mcp.json (Cursor), or .vscode/settings.json (VS Code). Provides 7 tools: parse, convert, formats, estimate, auth, auth-poll, and account.
Quick Start
import { DocParse } from '@ailang/parse'
const client = new DocParse({ apiKey: 'dp_your_key_here' });
const result = await client.parse('report.docx');
console.log(`${result.blocks.length} blocks, format: ${result.format}`);
for (const block of result.blocks) {
switch (block.type) {
case 'heading':
console.log(` H${block.level}: ${block.text}`);
break;
case 'table':
console.log(` Table: ${block.headers?.length} cols, ${block.rows?.length} rows`);
break;
case 'change':
console.log(` ${block.changeType} by ${block.author}: ${block.text}`);
break;
default:
console.log(` ${block.type}: ${block.text?.slice(0, 80)}`);
}
}
Parse Documents
const blocks = await client.parse('report.docx');
const markdown = await client.parse('report.docx', 'markdown');
const html = await client.parse('report.docx', 'html');
const mdMeta = await client.parse('report.docx', 'markdown+metadata');
const result = await client.parseFile('local/report.docx');
const result = await client.parseUrl(
'https://storage.googleapis.com/bucket/doc.docx?X-Goog-Signature=...',
'markdown+metadata',
);
console.log(result.status);
console.log(result.blocks);
console.log(result.metadata.title);
console.log(result.summary.tables);
console.log(result.markdown);
for (const s of result.sections) {
console.log(` ${s.heading}: ${s.markdown.slice(0, 60)}...`);
}
Response Metadata
Every parse result includes quota and request metadata from response headers:
const result = await client.parse('report.docx');
const meta = result.responseMeta;
console.log(meta.requestId);
console.log(meta.tier);
console.log(meta.quotaRemainingDay);
console.log(meta.quotaRemainingMonth);
console.log(meta.quotaRemainingAi);
console.log(meta.format);
console.log(meta.replayable);
Block Types
All 9 block types are fully typed:
import type { Block, Cell, ParseResult } from '@ailang/parse'
for (const block of result.blocks) {
if (block.type === 'section') {
console.log(`Section: ${block.kind}`);
for (const child of block.blocks ?? []) {
console.log(` ${child.type}: ${child.text}`);
}
}
}
API Key Management
API key resolution (checked in order):
- Explicit
apiKey in constructor options
DOCPARSE_API_KEY environment variable (Node.js)
- Saved credentials in
~/.config/ailang-parse/credentials.json
Use the device auth flow to get an API key. The user signs in once — the key is saved automatically and reused in future sessions.
import { DocParse } from '@ailang/parse';
const client = new DocParse();
await client.deviceAuth({ label: 'my-agent' });
const client = new DocParse();
const result = await client.parse('report.docx');
const usage = await client.keys.usage('keyId123', 'user123');
const newKey = await client.keys.rotate('keyId123', 'user123');
await client.keys.revoke('keyId123', 'user123');
Migrating from Unstructured
import { UnstructuredClient } from 'unstructured-client';
const client = new UnstructuredClient({ serverUrl: 'https://api.unstructured.io' });
import { UnstructuredClient } from '@ailang/parse'
const client = new UnstructuredClient({
serverUrl: 'https://api.parse.sunholo.com'
});
const elements = await client.general.partition({ file: 'report.docx' });
Error Handling
import { DocParse, DocParseError, AuthError, QuotaError } from '@ailang/parse'
try {
const result = await client.parse('file.docx');
} catch (e) {
if (e instanceof AuthError) console.log('Bad API key');
else if (e instanceof QuotaError) console.log('Quota exceeded');
else if (e instanceof DocParseError) {
console.log(`API error: ${e.statusCode}`);
console.log(` suggested fix: ${e.suggestedFix}`);
console.log(` details: ${JSON.stringify(e.details)}`);
console.log(` request ID: ${e.requestId}`);
}
}
Configuration
const client = new DocParse({
apiKey: 'dp_your_key',
baseUrl: 'https://your-deployment.run.app',
timeout: 120000,
});
Retry on transient failures
parse / parseFile can retry transient AI-provider failures (the server
returns 502/503/504, and marks safe-to-retry 5xx with
X-AilangParse-Replayable). Retry is off by default — opt in with retry:
const client = new DocParse({
apiKey: 'dp_your_key',
retry: {
maxRetries: 3,
retryableStatuses: [502, 503, 504],
respectReplayable: true,
backoffBaseMs: 1000,
backoffMaxMs: 30000,
},
});
Browser Usage
Works in browsers with native fetch:
<script type="module">
import { DocParse } from './node_modules/@ailang/parse/src/index.js';
const client = new DocParse({ apiKey: 'dp_your_key' });
const health = await client.health();
console.log(health.status);
</script>
License
Apache 2.0 — see LICENSE for details.
Links