This is the hello-world of ai_sdk. You only need two imports: the provider factory and the
generate_text
helper.1
Install dependencies
Make sure the environment variable
OPENAI_API_KEY
is set.2
Create a model instance & generate text
What just happened?
openai()
returns a LanguageModel wrapper that talks to the OpenAI Chat Completions API.generate_text()
sends the prompt, waits for the response, and returns a typedGenerateTextResult
.