Skip to content

Commit 2188698

Browse files
committed
docs: update openai provider docs
1 parent 72ded47 commit 2188698

File tree

1 file changed

+44
-32
lines changed

1 file changed

+44
-32
lines changed

apps/docs/content/docs/providers/index.mdx

Lines changed: 44 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -2,102 +2,114 @@
22
title: OpenAI
33
---
44

5-
AISDK supports OpenAI as a provider. You can use it to generate text, images, and other data.
5+
AISDK includes first-class support for the OpenAI.
66

7-
### Quick Installation
7+
## Installation
88

9-
To add the OpenAI provider, you can use the following command:
9+
Enable the OpenAI provider feature:
1010

1111
```bash
1212
cargo add aisdk --features openai
1313
```
1414

15-
### Manual Installation
15+
This installs AISDK with the OpenAI provider enabled.
1616

17-
To add the OpenAI provider manually, you can enable the `openai` feature in your `Cargo.toml` file:
17+
Once you have enabled the OpenAI provider, you can use all aisdk <Link href="/docs#core-features">features</Link> with it.
1818

19-
```toml
20-
[dependencies]
21-
aisdk = { version = "0.1.0", features = ["openai"] }
22-
```
19+
### Quick Start
20+
21+
Create an OpenAI provider instance with default settings:
22+
23+
```rust
24+
use aisdk::providers::openai::OpenAI;
2325

24-
This will install the OpenAI provider and its dependencies.
26+
let openai = OpenAI::new("gpt-5");
27+
```
2528

26-
### Usage
29+
This initializes the provider with:
2730

28-
Once you have installed the OpenAI provider, you can use all aisdk <Link href="/docs#core-features">features</Link> with it.
31+
* Model: `"gpt-5"`
32+
* API key from environment (if set with `OPENAI_API_KEY`)
33+
* OpenAI’s default base URL
2934

30-
#### Example Generating Text
35+
## Basic Text Generation
3136

3237
```rust
3338
use aisdk::{
34-
core::{LanguageModelRequest},
39+
core::LanguageModelRequest,
3540
providers::openai::OpenAI,
3641
};
3742

3843
#[tokio::main]
3944
async fn main() -> Result<(), Box<dyn std::error::Error>> {
4045

41-
// with default openai provider settings
46+
// Initialize provider with default settings.
4247
let openai = OpenAI::new("gpt-5");
4348

44-
let result = LanguageModelRequest::builder()
49+
let response = LanguageModelRequest::builder()
4550
.model(openai)
46-
.prompt("hello world")
51+
.prompt("Write a short poem about Rust.")
4752
.build()
4853
.generate_text()
49-
.await?;
54+
.await?
55+
.text()?;
5056

51-
println!("{}", result.text.unwrap());
57+
println!("Model output: {}", response);
5258
Ok(())
5359
}
5460
```
5561

56-
This will generate a response from the OpenAI provider.
57-
5862
## Provider Settings
5963

60-
You can customize the provider settings by passing them as arguments to the `OpenAI::builder()` method.
64+
You can customize provider configuration using `OpenAI::builder()`
6165

62-
#### API Key
63-
64-
To set the API key, you can use the `api_key` method:
66+
### API Key
6567

6668
```rust
6769
let openai = OpenAI::builder()
6870
.api_key("your-api-key")
6971
.build()?;
7072
```
7173

72-
#### Base URL
74+
If not specified, AISDK uses the `OPENAI_API_KEY` environment variable.
75+
76+
### Base URL
7377

74-
To set the base URL, you can use the `base_url` method:
78+
Useful when routing through a proxy, gateway, or self-hosted compatible endpoint.
7579

7680
```rust
7781
let openai = OpenAI::builder()
7882
.base_url("https://api.openai.com/v1")
7983
.build()?;
8084
```
8185

82-
#### Provider Name
86+
### Provider Name
8387

84-
To set the provider name, you can use the `provider_name` method:
85-
This is used for observability and logging purposes.
88+
For logging, analytics, and observability.
8689

8790
```rust
8891
let openai = OpenAI::builder()
8992
.provider_name("OpenAI")
9093
.build()?;
9194
```
9295

93-
#### Model Name
96+
### Model Name
9497

95-
To set the model name, you can use the `model_name` method:
98+
Set a default model for all requests using this provider instance:
9699

97100
```rust
98101
let openai = OpenAI::builder()
99102
.model_name("gpt-4o")
100103
.build()?;
101104
```
102105

106+
### Full Custom Configuration Example
103107

108+
```rust
109+
let openai = OpenAI::builder()
110+
.api_key("your-api-key")
111+
.base_url("https://api.openai.com/v1")
112+
.provider_name("OpenAI")
113+
.model_name("gpt-4o")
114+
.build()?;
115+
```

0 commit comments

Comments
 (0)