接口文档 curl调用示例 plaintext curl location ' header 'ContentType: application/json' header 'Authorization: Bearer ' data '{ "model": "TeleChat3438BA24B", "messages": [ { "role": "user", "content": "你好,一句话介绍一下你自己" } ], "stream": true }' Python调用示例 plaintext import requests url " apikey " " payload { "model": "TeleChat3438BA24B", "messages": [{"role": "user", "content": "你好,一句话介绍一下你自己"}], "stream": True, } resp requests.post( url, headers{ "ContentType": "application/json", "Authorization": f"Bearer {apikey}", }, jsonpayload, streamTrue, ) 流式解析 SSE for line in resp.iterlines(decodeunicodeTrue): if line and line.startswith("data:"): data line[len("data:"):].strip() if data "[DONE]": break print(data) Java调用示例(OkHttp + Jackson) plaintext import okhttp3.; import com.fasterxml.jackson.databind.ObjectMapper; public class ChatCompletionsExample { public static void main(String[] args) throws Exception { String url " String apiKey " "; ObjectMapper mapper new ObjectMapper(); String json mapper.writeValueAsString(java.util.Map.of( "model", "TeleChat3438BA24B", "messages", java.util.List.of( java.util.Map.of("role", "user", "content", "你好,一句话介绍一下你自己") ), "stream", true )); OkHttpClient client new OkHttpClient(); Request request new Request.Builder() .url(url) .addHeader("ContentType", "application/json") .addHeader("Authorization", "Bearer " + apiKey) .post(RequestBody.create(json, MediaType.get("application/json"))) .build(); try (Response response client.newCall(request).execute()) { // 非流式:直接打印 body System.out.println(response.body().string()); // 流式:通过 ResponseBody.source() 逐行读取 SSE,遇 [DONE] 结束 } } }