public  class  ChartGPTConfig  { private  final  String  apiKey; private  final  String  apiUrl; public  ChartGPTConfig ( String  apiKey,  String  apiUrl)  { this . apiKey =  apiKey; this . apiUrl =  apiUrl; } public  String  getApiKey ( )  { return  apiKey; } public  String  getApiUrl ( )  { return  apiUrl; } 
} 
public  class  ChartGPTExample  { public  static  void  main ( String [ ]  args)  { ChartGPTConfig  config =  new  ChartGPTConfig ( "YOUR_API_KEY" ,  "https://api.chartgpt.com/v1/generate" ) ; String  query =  "What is the population of China?" ;  try  { String  response =  callChartGPTAPI ( config,  query) ; System . out. println ( "Response: "  +  response) ; }  catch  ( IOException  e)  { e. printStackTrace ( ) ; } } private  static  String  callChartGPTAPI ( ChartGPTConfig  config,  String  query)  throws  IOException  { OkHttpClient  client =  new  OkHttpClient ( ) ; String  url =  config. getApiUrl ( )  +  "?query="  +  query; Request  request =  new  Request. Builder ( ) . url ( url) . addHeader ( "Authorization" ,  "Bearer "  +  config. getApiKey ( ) ) . build ( ) ; try  ( Response  response =  client. newCall ( request) . execute ( ) )  { return  response. body ( ) . string ( ) ; } } 
} 
< dependency> < groupId> </ groupId> < artifactId> </ artifactId> < version> </ version> </ dependency> 
dependencies { implementation 'com. squareup. okhttp3: okhttp: 4.9 .1 '
}