Skip to content

Support api_key parameter in Moderation.create method #122

@zafercavdar

Description

@zafercavdar

Description

create method in Moderation class initializes a new instance by calling parent constructor without any parameters. That's why it's impossible make Moderationendpoint calls without setting API key as environment variable or setting it through openai.api_key in contrast to Completion class.

How to reproduce

import openai

openai.api_key = None
moderator = openai.Moderation(api_key=api_key)

text = "hello world"
response = moderator.create(input=text, model="text-moderation-stable")

> AuthenticationError: No API key provided. You can set your API key in code using 'openai.api_key = <API-KEY>',
or you can set the environment variable OPENAI_API_KEY=<API-KEY>).
If your API key is stored in a file, you can point the openai module at it with 'openai.api_key_path = <PATH>'.
You can generate API keys in the OpenAI web interface. See https://onboard.openai.com for details, or email [email protected] if you have any questions.

Potential solution

  • Accept api_key parameter in Moderation.create
  • Pass api_key to super class

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions