Obtain code instead of tokens

Hi there!
I want to login user by creds.
I use this endpoint:

http://keycloak.local/auth/realms/demo/protocol/openid-connect/token

I send POST request with user creds and obtain access and refresh tokes.
But is there endpoint which will return me code. Like after success login via keycloak login form?

Apparently you are using direct grant flow. Use different flow (e. g. authorisation code flow) and make sure you have suitable client configuration for that. Be familiar how selected flow works (e. g. you need to create request for auth endpoint first to obtain code, then that code will be used in the token request,…).