The boson-fermion correspondence of type A is an isomorphism between two super vertex algebras (and so has singularities in the operator product expansions only at z = w). The boson-fermion correspondence of type B plays similarly important role in many areas, including representation theory, integrable systems, random matrix theory and random processes. But the vertex operators describing it have singularities in their operator product expansions at both z = w and z = −w, and thus need a more general notion than that of a super vertex algebra. In this paper we present such a notion: the concept of a twisted vertex algebra, which generalizes the concept of super vertex algebra. The two sides of the correspondence of type B constitute two examples of twisted vertex algebras. The boson-fermion correspondence of type B is thus an isomorphism between two twisted vertex algebras.