Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issues with sending requests containing certain characters #83

Open
cal-anthropic opened this issue Dec 19, 2024 · 1 comment
Open

Issues with sending requests containing certain characters #83

cal-anthropic opened this issue Dec 19, 2024 · 1 comment

Comments

@cal-anthropic
Copy link

Repro

package main

import (
	"context"
	"os"

	"github.com/anthropics/anthropic-sdk-go"
	"github.com/anthropics/anthropic-sdk-go/option"
)

func main() {
	client := anthropic.NewClient(
		option.WithAPIKey(os.Getenv("ANTHROPIC_API_KEY")),
	)
	message, err := client.Messages.New(context.TODO(), anthropic.MessageNewParams{
		Model:     anthropic.F(anthropic.ModelClaude3_5SonnetLatest),
		MaxTokens: anthropic.F(int64(1024)),
		Messages: anthropic.F([]anthropic.MessageParam{
			anthropic.NewUserMessage(anthropic.NewTextBlock("What is a quaternion?\x1b")),
		}),
	})
	if err != nil {
		panic(err.Error())
	}
	println(message.Content[0].Text)
}

Output:

POST "https://api.anthropic.com/v1/messages": 400 Bad Request {"type":"error","error":{"type":"invalid_request_error","message":"The request body is not valid JSON: invalid escaped character in string: line 1 column 75 (char 74)"}}
@gdsoumya
Copy link

gdsoumya commented Jan 2, 2025

+1 having similar issues :

{\"type\":\"error\",\"error\":{\"type\":\"invalid_request_error\",\"message\":\"The request body is not valid JSON: invalid escaped character in string: line 1 column 1597 (char 1596)\"}}"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants