View Source OpenAi.Config (OpenAI REST API Client v0.4.4)
Module responsible for managing the configuration of the OpenAI API client.
You can configure openai in your mix config.exs (default $project_root/config/config.exs). If you're using Phoenix add the configuration in your config/dev.exs|test.exs|prod.exs files. An example config is:
config :oapi_open_ai,
# find it at https://platform.openai.com/account/api-keys
api_key: "your-api-key",
# optional, use when required by an OpenAI API beta, e.g.:
beta: "assistants=v1",
# optional, HTTP client defaults to HTTPoison, useful for mocking in tests
http_client: HTTPoisonMock,
# optional, passed to HTTPoison.Request options
http_options: [recv_timeout: 30_000]
Note: you can load your os ENV variables in the configuration file, if you set an env variable for API key named OPENAI_API_KEY
you can get it in the code by doing System.get_env("OPENAI_API_KEY")
.
More info on possible http_options
configuration: HTTPoison.Request
The config.exs
is compile time, so the get_env/1
function is executed during the build, if you want to get the env variables during runtime please use runtime.exs
instead of config.exs
in your application (elixir doc ref).
Summary
Functions
Returns the API key for the OpenAI API.
Returns the base URL for the OpenAI API. Defaults to "https://api.openai.com/v1/".
Returns the HTTP client module to use for making requests. Defaults to HTTPoison.
Returns the HTTP headers to include in the request.
Functions
Returns the API key for the OpenAI API.
This is required for making requests to the API. find it at https://platform.openai.com/account/api-keys
Returns the base URL for the OpenAI API. Defaults to "https://api.openai.com/v1/".
Returns the HTTP client module to use for making requests. Defaults to HTTPoison.
This is useful for testing, where you might want to use a mock HTTP client.
Returns the HTTP headers to include in the request.
Will throw if the headers are not a list.