"ChatGPT" API Server with Next.js
- via OpenAI's official text completion API
- using "text-davinci-003"
- not free, but you have some free credits to try it out
- need OPENAI_API_KEY
- Powered by transitive-bullshit/chatgpt-api
To deploy your instance of this API with Vercel, either click this button
or follow these steps:
- clone/fork this repository
- import this project into Vercel
- enter the environment variable OPENAI_API_KEY = your_openai_api_key
- API will be available at https://your-vercel-project-name.vercel.app/api/chat
- Note that the above URL is just an example. You can find your own URL in the Vercel dashboard.
API usage
-
POST to https://your-vercel-project-name.vercel.app/api/chat
{
"message": "Hello, how are you?"
}
e.g. curl
curl -i -X POST \
-H "Content-Type:application/json" \
-d \
'{
"message": "Can you chat?"
}' \
'https://your-vercel-project-name.vercel.app/api/chat'
-
Response
{
"response": "I can chat, but I'm not sure what you mean."
}
Logging
The server logs all incoming requests and their corresponding responses to help with debugging and monitoring the API usage. To effectively utilize the logging for testing and debugging, it's crucial to follow best practices.
Best Practices for Testing and Debugging Using Logs
- Consistent Log Format: Ensure your logs follow a consistent format to make them easier to read and analyze. For example, each log entry should include a timestamp, the log level (INFO, ERROR, DEBUG), and a clear message describing the event.
- Use Log Levels Appropriately: Utilize different log levels to categorize the importance of the log entries. DEBUG logs are useful for development, while ERROR logs are crucial for identifying issues in production.
- Filtering and Analysis Tools: Employ tools like Logstash or Splunk for filtering and analyzing log data. These tools can help you quickly find relevant log entries and identify patterns or issues.
- Regular Monitoring: Set up a routine for monitoring logs, especially for ERROR and WARNING levels, to catch and address issues promptly.
Interpreting Common Log Entries
- 404 Not Found: This indicates that the requested resource was not found on the server. It's often a sign of a broken link or a mistyped URL.
- 500 Internal Server Error: A generic error message indicating that the server encountered an unexpected condition. This requires further investigation into the server logs to identify the specific issue.
- 401 Unauthorized: This status code is returned when a user tries to access a resource that they are not authorized to view. It suggests issues with authentication or permissions.
By following these best practices and learning to interpret common log entries, developers and users can significantly improve their ability to test and debug using logs.