Error trying to compare levels from a binomial model

Hi,
I have been trying to compare levels from a binomial model.
If I try the following, I run into and error:

fit1 <- brm(incidence | trials(size) ~ period + (1|herd),
            data = cbpp, family = binomial())


cbpp%>%add_epred_draws(fit1, re_formula = NA)%>% 
  compare_levels(variable = .epred,by="period") %>% 
  mean_qi()

Error in combn(levels(x), 2, simplify = FALSE) : n < m

If I try:

cbpp%>%dplyr::select(period)%>%unique()%>%add_epred_draws(fit1, re_formula = NA)%>% 
  compare_levels(variable = .epred,by="period") %>% 
  mean_qi()

Error: The following variables can neither be found in 'data' nor in 'data2':
'size'

Any suggestions of how to make it work?

Thanks

I will answer myself. The package ‘marginaleffects’ was the solution for me.
For comparisons:

options("marginaleffects_posterior_center" = "mean")
avg_comparisons(fit1,variables = list(period = "pairwise"),re_formula=NA)

For point estimates:

cbpp%>%add_epred_draws(fit1, re_formula = NA)%>%group_by(period)%>%
  mean_qi(.epred)

or

predictions(fit1,re_formula=NA, by="period")%>%posterior_draws()%>%group_by(period)%>%mean_qi(draw)

I still wanted compare levels to work though…

Thanks for providing the answer @daSilva5. I marked it as solved.