| Crates.io | tencentcloud-hunyuan-sdk |
| lib.rs | tencentcloud-hunyuan-sdk |
| version | 0.1.4 |
| created_at | 2025-08-09 06:54:19.024532+00 |
| updated_at | 2025-09-14 07:57:56.3283+00 |
| description | TencentCloud Hunyuan SDK for Rust |
| homepage | https://github.com/y-zion/tencentcloud-hunyuan-sdk-rust |
| repository | https://github.com/y-zion/tencentcloud-hunyuan-sdk-rust |
| max_upload_size | |
| id | 1787630 |
| size | 102,390 |
A Rust SDK for TencentCloud Hunyuan, offering a full-featured, async-first interface to the Hunyuan API (v2023-09-01).
ChatCompletions and a generic call_actionAdd this to your Cargo.toml:
[dependencies]
tencentcloud-hunyuan-sdk = "0.1.4"
use tencentcloud_hunyuan_sdk::{Client, ClientBuilder, Credential, Region};
use tencentcloud_hunyuan_sdk::models::{ChatCompletionsRequest, Message};
#[tokio::main]
async fn main() -> anyhow::Result<()> {
// Set credentials via env or read from a config vault
let secret_id = std::env::var("TENCENTCLOUD_SECRET_ID")?;
let secret_key = std::env::var("TENCENTCLOUD_SECRET_KEY")?;
let client: Client = ClientBuilder::new()
.credential(Credential { secret_id, secret_key, token: None })
.region(Region::ApGuangzhou)
.debug(true) // or set env var TENCENTCLOUD_SDK_DEBUG=true
.build();
let req = ChatCompletionsRequest {
model: Some("hunyuan-lite".to_string()),
messages: vec![
Message { role: "user".into(), content: "Hello, Hunyuan!".into() },
],
temperature: Some(0.7),
top_p: Some(0.95),
// Add more fields as needed per API
stream: Some(false),
};
let resp = client.chat_completions(&req).await?;
println!("{:?}", resp);
Ok(())
}
Environment variables used in the example:
TENCENTCLOUD_SECRET_IDTENCENTCLOUD_SECRET_KEYOptionally, if you use temporary credentials, provide session token through Credential { token: Some("...".into()), .. } which is sent as X-TC-Token.
reqwest with configurable TLS backendsChatCompletions plus standard response envelopeThis SDK provides two TLS backends for HTTP requests:
rustls-tls (default): Uses the rustls TLS implementation. This is the default and recommended for most use cases.native-tls: Uses the system's native TLS implementation (OpenSSL on Linux/macOS, SChannel on Windows).[dependencies]
tencentcloud-hunyuan-sdk = "0.1.4"
[dependencies]
tencentcloud-hunyuan-sdk = { version = "0.1.4", default-features = false, features = ["native-tls"] }
You must ensure the container has proper CA certificates installed. The rustls or native-tls backend requires these to verify SSL certificates.
# Debian/Ubuntu
RUN apt-get update && apt-get install -y ca-certificates && rm -rf /var/lib/apt/lists/*
# Alpine
RUN apk add --no-cache ca-certificates
# Copy from host (if using minimal images)
COPY /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/
The default endpoint is hunyuan.tencentcloudapi.com and the default region is ap-guangzhou.
use tencentcloud_hunyuan_sdk::{ClientBuilder, Credential, Region};
let client = ClientBuilder::new()
.credential(Credential { secret_id, secret_key, token: None })
.region(Region::ApBeijing) // or Region::ApGuangzhou, or Region::Custom("ap-shanghai".into())
.build();
You can also override the endpoint:
let client = ClientBuilder::new()
.credential(cred)
.endpoint("hunyuan.tencentcloudapi.com")
.build();
Errors are returned as SdkError and include:
code, message, request_id)Example pattern:
match client.chat_completions(&req).await {
Ok(resp) => println!("ok: {:?}", resp),
Err(e) => eprintln!("error: {}", e),
}
You can enable SDK debug logs to print key request/response information with sensitive fields masked.
ClientBuilder::new().debug(true)TENCENTCLOUD_SDK_DEBUG=true (also accepts 1/on)When enabled, the SDK prints:
AuthorizationNote: Do not post debug logs publicly; while signatures and secrets are masked, request/response bodies may contain sensitive data.
Beyond the provided chat_completions helper, you can call any action supported by the Hunyuan API via the generic caller (exposed internally by the client). To add new typed actions, define the request/response models in models.rs and forward to call_action("ActionName", &req).
Refer to the Go SDK models for exact shapes to mirror.
Run the included example after exporting credentials:
export TENCENTCLOUD_SECRET_ID=... \
export TENCENTCLOUD_SECRET_KEY=...
cargo run --example chat
src/models.rssrc/client.rsThis project uses the license provided in LICENSE.
This SDK is based on the TencentCloud Go SDK (Hunyuan v20230901) implementation by Cursor and follows the same API patterns and structure for consistency across different language SDKs.