OpenAI API client library for Rust (unofficial)
The OpenAI API client Rust library provides convenient access to the OpenAI API from Rust applications.
Check out the docs.rs.
Installation:
Cargo.toml
[]
= "4.1.0"
Usage
The library needs to be configured with your account's secret key, which is available on the website. We recommend setting it as an environment variable. Here's an example of initializing the library with the API key loaded from an environment variable and creating a completion:
Set OPENAI_API_KEY to environment variable
Create client
let client = new;
Create request
let req = new;
Send request
let result = client.chat_completion?;
println!;
Set OPENAI_API_BASE to environment variable (optional)
Example of chat completion
use Client;
use ;
use GPT4_O;
use env;
More Examples: examples
Check out the full API documentation for examples of all the available functions.
Supported APIs
- completions
- Chat
- Edits
- Images
- Embeddings
- Audio
- Files
- Fine-tuning
- Moderations
- Function calling
- Assistants
License
This project is licensed under MIT license.