pub struct Client { /* private fields */ }Expand description
A client for interacting with the DeepSeek API.
§Example
#[tokio::main]
async fn main() {
use deepseek_api::Client;
let api_key = "your_api_key";
let client = Client::new(api_key);
// Get available models
let models = client.models().await.unwrap();
// Get user balance
let balance = client.balance().await.unwrap();
// Create a chat completion
let chat = client.chat();
}§Fields
client- The underlying HTTP client.host- The base URL for the DeepSeek API.
Implementations§
Source§impl Client
impl Client
Sourcepub fn new(api_key: &str) -> Self
pub fn new(api_key: &str) -> Self
Creates a new Client instance with the provided API key.
This method initializes the client with the necessary headers, including the authorization header with the provided API key.
§Arguments
api_key- A string slice that holds the API key for authorization.
§Returns
A new instance of the Client struct.
§Panics
This function will panic if the HeaderValue cannot be created from the
provided API key or if the Client cannot be built.
§Example
use deepseek_api::Client;
let client = Client::new("your_api_key");pub fn chat(&self) -> ChatCompletions
Sourcepub async fn models(&self) -> Result<ModelResp>
pub async fn models(&self) -> Result<ModelResp>
Retrieves the list of available models from the DeepSeek API.
This method sends a GET request to the /models endpoint of the DeepSeek API
and returns a Result containing a ModelResp on success.
§Errors
This function will return an error if the request fails or if the response
cannot be deserialized into a ModelResp.
§Example
#[tokio::main]
async fn main() {
use deepseek_api::Client;
let client = Client::new("your_api_key");
let models = client.models().await.unwrap();
println!("{:?}", models);
}For more information, see the DeepSeek API documentation.
Sourcepub async fn balance(&self) -> Result<BalanceResp>
pub async fn balance(&self) -> Result<BalanceResp>
Retrieves the balance information of the user from the DeepSeek API.
This method sends a GET request to the /user/balance endpoint of the DeepSeek API
and returns a Result containing a BalanceResp on success.
§Errors
This function will return an error if the request fails or if the response
cannot be deserialized into a BalanceResp.
§Example
#[tokio::main]
async fn main() {
use deepseek_api::Client;
let client = Client::new("your_api_key");
let balance = client.balance().await.unwrap();
println!("{:?}", balance);
}For more information, see the DeepSeek API documentation.