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
[]
= "3.0.1"
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
Set OPENAI_API_BASE to environment variable (optional)
Create client
use Client;
use env;
let client = new;
Create request
use ;
use GPT4;
let req = new;
Send request
let result = client.completion?;
println!;
Example of chat completion
use Client;
use ;
use GPT4;
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-tunes
- Moderations
- Function calling
- Assistants
License
This project is licensed under MIT license.