Skip to content
Follow yggy on LinkedInFollow @yggy_tech on X

Rust SDK

The Rust SDK is an async client built on reqwest. The source is at github.com/yggy-tech/yggy-sdk-rust.

The yggy-sdk crate on crates.io is coming soon. Until then, depend on the tagged release of the repository:

[dependencies]
yggy-sdk = { git = "https://github.com/yggy-tech/yggy-sdk-rust", tag = "v0.1.0" }
reqwest = "0.12"
tokio = { version = "1", features = ["full"] }

Create an API key in yggy under Developers → API keys and keep it in the YGGY_API_KEY environment variable. A key that belongs to one organization needs nothing else. A personal key can see several organizations, so name the one you want in the x-yggy-organization-id header, by id or slug, as the examples do. See Authentication for key types and permissions.

List the projects your key can see:

use reqwest::header::{HeaderMap, HeaderValue};
use yggy_sdk::apis::{configuration::{ApiKey, Configuration}, projects_api};
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let mut headers = HeaderMap::new();
headers.insert("x-yggy-organization-id", HeaderValue::from_static("acme-corp"));
let mut configuration = Configuration::new();
configuration.client = reqwest::Client::builder().default_headers(headers).build()?;
configuration.api_key = Some(ApiKey { prefix: None, key: std::env::var("YGGY_API_KEY")? });
let response = projects_api::list_projects(&configuration, None, None, None, None, None).await?;
for project in response.projects {
println!("{}", project.name);
}
Ok(())
}

Operations are free functions in one module per group, for example projects_api, documents_api and query_api. Each takes &Configuration first and then the parameters in the order of the Reference. Optional parameters are Option values.

This sample takes the id of a document that has already been uploaded to project 0xproject, prints its status and extracted facts, and asks a question. See Read extracted facts for what the calls return.

use reqwest::header::{HeaderMap, HeaderValue};
use yggy_sdk::apis::{configuration::{ApiKey, Configuration}, documents_api, query_api};
use yggy_sdk::models::QueryProjectRequest;
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let mut headers = HeaderMap::new();
headers.insert("x-yggy-organization-id", HeaderValue::from_static("acme-corp"));
let mut configuration = Configuration::new();
configuration.client = reqwest::Client::builder().default_headers(headers).build()?;
configuration.api_key = Some(ApiKey { prefix: None, key: std::env::var("YGGY_API_KEY")? });
let project_id = "0xproject";
let document_id = std::env::args().nth(1).expect("document id");
let status = documents_api::get_document_status(&configuration, project_id, &document_id, None).await?;
println!("completed={} failed={}", status.completed, status.failed);
let triples = documents_api::list_document_triples(&configuration, project_id, &document_id, None).await?;
for t in triples.triples {
println!("{} {} {}", t.subject, t.predicate, t.object);
}
let request = QueryProjectRequest::new("Which contracts renew in Q1?".to_string());
let answer = query_api::query_project(&configuration, project_id, None, Some(request)).await?;
println!("{}", answer.answer);
Ok(())
}

Document upload from the Rust SDK is coming soon: the generated upload_document does not send the file yet. Until it does, upload with the CLI or the REST API, then read the results with the SDK as above.

Every call returns Result<_, Error<_>>. The error is one of Reqwest (network), Serde (unreadable response), Io or ResponseError, which carries the HTTP status and the raw content with the error code.

use yggy_sdk::apis::Error;
match projects_api::list_projects(&configuration, None, None, None, None, None).await {
Err(Error::ResponseError(response)) => eprintln!("{} {}", response.status, response.content),
Err(other) => return Err(other.into()),
Ok(_) => {}
}

See Errors and rate limits for the codes and for 429 handling. Honour the Retry-After header before you retry.