Creating a Client
TheOpenAI::Client class is the main entry point for interacting with the OpenAI API. Create a client instance to access all API resources.
Basic Usage
Configuration Options
The client accepts the following initialization parameters:Your OpenAI API key. Defaults to
ENV["OPENAI_API_KEY"].Your organization ID for multi-organization accounts. Defaults to
ENV["OPENAI_ORG_ID"].Sets the openai-organization header on all requests.Your project ID for project-scoped requests. Defaults to
ENV["OPENAI_PROJECT_ID"].Sets the openai-project header on all requests.Secret key for validating webhook signatures. Defaults to
ENV["OPENAI_WEBHOOK_SECRET"].Override the default API base URL. Defaults to
ENV["OPENAI_BASE_URL"] or "https://api.openai.com/v1".Useful for testing or using proxy servers.Maximum number of retry attempts for failed requests. See Retries for details.
Initial delay in seconds before the first retry attempt. See Retries for details.
Maximum delay in seconds between retry attempts. See Retries for details.
Environment Variables
Advanced Configuration
Custom Base URL
Multiple Organizations
Custom Retry and Timeout Behavior
Available Resources
Once initialized, the client provides access to all API resources:See the API reference for detailed documentation on each resource.