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:

 @Bean
    @Order(1)
    public SecurityFilterChain apiFilterChain(HttpSecurity http) throws Exception {
        http
                .securityMatcher(AntPathRequestMatcher.antMatcher("/api/**"))
                .csrf(csrf -> csrf.ignoringRequestMatchers(new AntPathRequestMatcher("/api/**")))
                .authorizeHttpRequests(authorize -> authorize.
                        anyRequest().permitAll()
                );
        return http.build();
    }

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

What i am doing wrong?