package clientserver; import java.io.FileInputStream; import java.io.IOException; import java.net.URI; import java.net.http.HttpClient; import java.net.http.HttpRequest; import java.net.http.HttpResponse; import java.util.Properties; public class MistralDirectAPI { public static void main(String[] args) { String apiKey; // Load API key from properties file try { Properties props = new Properties(); FileInputStream input = new FileInputStream("config.properties"); props.load(input); apiKey = props.getProperty("mistral.api.key"); input.close(); } catch (IOException e) { System.err.println("Could not load API key: " + e.getMessage()); return; } String payload = """ { "model": "mistral-medium", "messages": [ { "role": "user", "content": "Reverse turing test." } ] } """; HttpRequest request = HttpRequest.newBuilder() .uri(URI.create("https://api.mistral.ai/v1/chat/completions")) .header("Authorization", "Bearer " + apiKey) .header("Content-Type", "application/json") .POST(HttpRequest.BodyPublishers.ofString(payload)) .build(); HttpClient client = HttpClient.newHttpClient(); try { HttpResponse response = client.send( request, HttpResponse.BodyHandlers.ofString() ); System.out.println("Response Code: " + response.statusCode()); System.out.println("Response Body: " + response.body()); } catch (IOException | InterruptedException e) { System.err.println("Error occurred: " + e.getMessage()); } } }