Cargo.toml
·ThisToken.AI·
Tutorials入门教程ThisToken.AI
[dependencies]
async-openai = "0.24"
tokio = { version = "1", features = ["full"] }
use async_openai::{
config::OpenAIConfig,
types::{CreateMessageRequestArgs, Message, RunTool, ThreadMessage},
Client,
};
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let config = OpenAIConfig::new()
.with_api_key(std::env::var("THISTOKEN_API_KEY")?)
.with_api_base("https://api.thistoken.ai/v1");
let client = Client::with_config(config);
// 后续调用 chat.completions 等接口,写法与官方端点一致
println!("client ready: {:?}", client);
Ok(())
}
Once this runs, you'll notice: you write all request code exactly once, and switching models or tiers is just a configuration-level change.
## Before and After: Where the Time Went
| Step | Traditional Approach (Direct Multi-Vendor) | Unified Gateway |
|------|--------------------------------------|----------|
| Registration & Key management | Once per platform | Once |
| Request wrappers | One per vendor | One |
| Switching models | Change code and dependencies | Change a model-name string |
| First successful run | Half a day minimum | ~25 minutes |
Of course, a unified gateway isn't a silver bullet—retry strategies, timeout settings, and cancellation logic for streaming responses still need your own review based on your business scenario. But at least you won't burn time on repetitive integration work.
If you happen to have a Rust project and want to add LLM capabilities, why not spend the time of a cup of coffee registering now: https://api.thistoken.ai/register
---
Ready to try it yourself? Sign up at https://api.thistoken.ai/register to get your API key and start building.Bạn muốn thử Token.AI?
Tạo API Key cấp dự án, bật kênh trong bảng điều khiển và định cấu hình định tuyến, ngân sách và nhật ký kiểm tra.
注册 ThisToken.AI 并获取 API Key