Novik
Novik

Reputation: 3

Cronjob message: "you didnt provide an API-Key"

I have the following problem. I want to run a cronjob once a day within a Docker container

@daily /usr/local/bin/php /var/www/html/Tests/example.php

This script sends requests to ChatGPT. The corresponding OpenAIKey is stored in docker-compose.yaml as an enviroment variable. The OpenAIKey was previously hardcoded but has now been moved to an .env file (contains only OpenAIKey). When the key was still hardcoded, the cronjob still worked fine and manual execution of the example.php is also possible now. The .env was therefore correctly integrated into the existing code. However, as soon as the cronjob is supposed to execute the example.php (with .env-file) the following error appears within the Docker container:

"error": { "message": "You didn't provide an API key. You need to provide your API key in an Authorization header using Bearer auth (i.e. Authorization: Bearer YOUR_KEY), or as the password field (with blank username) if you're accessing the API from your browser and are prompted for a username and password. You can obtain an API key from https://platform.openai.com/account/api-keys.", "type": "invalid_request_error", "param": null, "code": null } }

Unfortunately I do not know how to fix this error, it was not possible via a bash-script. Adding the key as source in the crontab did not work either ->

@daily source ../openAIKey.env && /usr/local/bin/php /var/www/html/Tests/example.php 2> /var/www/html/Tests/errPress.txt >> /var/www/html/Tests/errPress.txt

Upvotes: 0

Views: 73

Answers (0)

Related Questions