pub struct DatalabClient { /* private fields */ }Expand description
Async client for the DataLab Marker REST API.
§Authentication
All requests require an API key sent via the X-API-Key header.
Create the client with DatalabClient::new or load from the
DATALAB_API_KEY environment variable with DatalabClient::from_env.
§Usage
use papers_datalab::{DatalabClient, MarkerRequest, OutputFormat, ProcessingMode};
let client = DatalabClient::from_env()?;
let pdf_bytes = std::fs::read("paper.pdf").unwrap();
let result = client.convert_document(MarkerRequest {
file: Some(pdf_bytes),
filename: Some("paper.pdf".into()),
output_format: vec![OutputFormat::Markdown],
mode: ProcessingMode::Accurate,
..Default::default()
}).await?;
println!("{}", result.markdown.unwrap_or_default());Implementations§
Source§impl DatalabClient
impl DatalabClient
Sourcepub fn with_base_url(self, url: impl Into<String>) -> Self
pub fn with_base_url(self, url: impl Into<String>) -> Self
Override the base URL. Useful for testing with a mock server.
Sourcepub fn from_env() -> Result<Self>
pub fn from_env() -> Result<Self>
Create a client from the DATALAB_API_KEY environment variable.
Returns DatalabError::MissingApiKey if the variable is not set.
Sourcepub async fn convert_document(
&self,
req: MarkerRequest,
) -> Result<MarkerPollResponse>
pub async fn convert_document( &self, req: MarkerRequest, ) -> Result<MarkerPollResponse>
High-level: submit a document and poll until conversion is complete.
Uses a 2-second poll interval. Returns the completed MarkerPollResponse
or an error if the job fails. No timeout is applied — the caller is
responsible for cancellation if needed.
Sourcepub async fn submit_marker(
&self,
req: MarkerRequest,
) -> Result<MarkerSubmitResponse>
pub async fn submit_marker( &self, req: MarkerRequest, ) -> Result<MarkerSubmitResponse>
POST /api/v1/marker — submit a conversion job.
Returns immediately with a request_id. Use get_marker_result
to poll for the result, or call convert_document to do both.
Sourcepub async fn get_marker_result(
&self,
request_id: &str,
) -> Result<MarkerPollResponse>
pub async fn get_marker_result( &self, request_id: &str, ) -> Result<MarkerPollResponse>
GET /api/v1/marker/{request_id} — poll for a single conversion result.
Returns the current state of the job. status will be processing,
complete, or failed. Poll every 2 seconds until complete or failed.
Sourcepub async fn list_step_types(&self) -> Result<StepTypesResponse>
pub async fn list_step_types(&self) -> Result<StepTypesResponse>
GET /api/v1/workflows/step-types — list available workflow step types.
Trait Implementations§
Source§impl Clone for DatalabClient
impl Clone for DatalabClient
Source§fn clone(&self) -> DatalabClient
fn clone(&self) -> DatalabClient
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more