Registry / http-client / async-openai

async-openai

JSON →
library0.39.0rscratesunverified

Rust library for OpenAI API, providing async access to models, completions, and more.

# Cargo.toml [dependencies] async-openai = "0.39.0"
INSTALL
IMPORT
SIG · ASYNC-OPENAI
A
async-openai
http-clientrustv0.39.0
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

Client
use async_openai::Client;

Creates an OpenAI client and sends a completion request.

use async_openai::Client; use async_openai::types::CreateCompletionRequest; #[tokio::main] async fn main() { let client = Client::new(); let request = CreateCompletionRequest { model: "text-davinci-003".to_string(), prompt: Some("Say hello".to_string()), max_tokens: Some(5), ..Default::default() }; let response = client.completions().create(request).await.unwrap(); println!("Response: {:?}", response); }
Debug
Known issues
gotchaRequires an async runtime like Tokio.
fix
Add tokio as a dependency and use #[tokio::main].
affects: >=0.39.0
gotchaAPI key must be set via environment variable OPENAI_API_KEY.
fix
Set OPENAI_API_KEY before running.
affects: >=0.1.0
Upgrade
Version history
0.39.0latest on crates.io
Audit
Dependencies

No dependency data recorded yet.

Agent activity
48 hits · last 30 days
node
42
OpenAI (training)
1
Resources
async-openai — cargo add async-openai · libregistry