Compounds having kappa opioid agonist activity, compositions containing them and method of using them as analgesics are provided.The compounds of formulae I, II, III and IV have the structure:wherein:X, X4, X5, X7, X9;R1, R2, R3, R4; andY, Z and n are as described in the specification.