Avoid redirect to login when calling api endpoints.

Hi I have a monolith that uses Vaadin 24 with Spring Security and Spring Boot.
I am facing an issue where I want my application to not redirect to the login page each time I make a call to my endpoints implemented with @RestController. I was able to configure the endpoints so they are open for everyone and the application released under spring security. But every time my endpoin return an error the endpoin returns the login page. I don’t want that.
My security configuration:

    public SecurityFilterChain apiFilterChain(HttpSecurity http) throws Exception {
                .csrf(csrf -> csrf.ignoringRequestMatchers(new AntPathRequestMatcher("/api/**")))
                .authorizeHttpRequests(authorize -> authorize.
        return http.build();

    protected void configure(HttpSecurity http) throws Exception {
        http.csrf(csrf -> csrf.ignoringRequestMatchers(new AntPathRequestMatcher("/api/**")));
        setLoginView(http, LoginView.class);

What i am doing wrong?