(c *gin.Context)
| 593 | } |
| 594 | |
| 595 | func (h *Handler) imageGenerations(c *gin.Context) { |
| 596 | var imageRequest officialtypes.ImageGenerationRequest |
| 597 | err := c.BindJSON(&imageRequest) |
| 598 | if err != nil { |
| 599 | c.JSON(400, gin.H{"error": gin.H{ |
| 600 | "message": "Request must be proper JSON", |
| 601 | "type": "invalid_request_error", |
| 602 | "param": nil, |
| 603 | "code": err.Error(), |
| 604 | }}) |
| 605 | return |
| 606 | } |
| 607 | if imageRequest.Prompt == "" { |
| 608 | c.JSON(400, gin.H{"error": gin.H{ |
| 609 | "message": "Missing required parameter: prompt", |
| 610 | "type": "invalid_request_error", |
| 611 | "param": "prompt", |
| 612 | "code": "missing_required_parameter", |
| 613 | }}) |
| 614 | return |
| 615 | } |
| 616 | if imageRequest.N <= 0 { |
| 617 | imageRequest.N = 1 |
| 618 | } |
| 619 | if imageRequest.N > 10 { |
| 620 | imageRequest.N = 10 |
| 621 | } |
| 622 | if imageRequest.ResponseFormat == "" { |
| 623 | imageRequest.ResponseFormat = "b64_json" |
| 624 | } |
| 625 | |
| 626 | proxyUrl := h.proxy.GetProxyIP() |
| 627 | secret, status, err := h.secretFromAuthorization(c, true, true, proxyUrl) |
| 628 | if err != nil { |
| 629 | c.JSON(status, gin.H{"error": gin.H{ |
| 630 | "message": err.Error(), |
| 631 | "type": "authorization_error", |
| 632 | "param": "Authorization", |
| 633 | "code": status, |
| 634 | }}) |
| 635 | return |
| 636 | } |
| 637 | if secret == nil || secret.Token == "" { |
| 638 | c.JSON(400, gin.H{"error": "Images API requires a logged-in ChatGPT access token."}) |
| 639 | c.Abort() |
| 640 | return |
| 641 | } |
| 642 | if secret.IsFree { |
| 643 | c.JSON(403, gin.H{"error": "Images API does not support free/noauth accounts. Use a ChatGPT access token."}) |
| 644 | return |
| 645 | } |
| 646 | |
| 647 | client := bogdanfinn.NewStdClient() |
| 648 | turnStile, status, err := h.initTurnStileWithRetry(&client, &secret, proxyUrl) |
| 649 | if err != nil { |
| 650 | c.JSON(status, gin.H{ |
| 651 | "message": err.Error(), |
| 652 | "type": "InitTurnStile_request_error", |
nothing calls this directly
no test coverage detected