The resource best suited to this problem is RoutePattern, and its representative_trip relationship. For example, if you were using the endpoint /route_patterns, you would include the representative_trip relationship with a list of the representative_trip's stop IDs, i.e. /route_patterns?include=representative_trip.stops (the order of stops in a Trip is the same order in which they occur along that trip). Then you would go through these RoutePatterns, associate each with its representative_trip, find which ones contain the stop_ids you're looking for in the expected order, and look at the direction_id.
One thing to watch out for is that it's theoretically possible for a given origin and destination stop_id to appear in the same order in RoutePatterns with two different directions. In this case, your code should probably raise an error, as the direction of the trip cannot be determined from just two stops.