POST /v1/chat/completions and get one completed response. For new integrations, the Responses API gives one request shape for text, multimodal input, tools and richer output items.
const chat = await client.generateText({
model: "openai/gpt-6-astra",
messages: [
{ role: "system", content: "You are helpful." },
{ role: "user", content: "Write a limerick about lighthouses." },
],
});
console.log(chat.choices[0].message.content);
chat = client.generate_text({
"model": "openai/gpt-6-astra",
"messages": [
{"role": "system", "content": "You are helpful."},
{"role": "user", "content": "Write a limerick about lighthouses."},
],
})
print(chat["choices"][0]["message"]["content"])
import (
"context"
"fmt"
phaseo "github.com/phaseoteam/Phaseo/packages/sdk/sdk-go/v3"
)
client, err := phaseo.NewFromEnv()
if err != nil {
panic(err)
}
resp, err := client.GenerateText(context.Background(), phaseo.ChatCompletionsRequest{
Model: "openai/gpt-6-astra",
Messages: []map[string]interface{}{
{"role": "user", "content": "Write a one-line haiku."},
},
})
if err != nil {
panic(err)
}
fmt.Println(resp["choices"])
using PhaseoSdk;
var client = new Phaseo();
var response = await client.GenerateText(new Dictionary<string, object>
{
["model"] = "openai/gpt-6-astra",
["messages"] = new[]
{
new Dictionary<string, object>
{
["role"] = "user",
["content"] = "Write a limerick about lighthouses.",
},
},
});
<?php
require 'vendor/autoload.php';
use Phaseo\Sdk\Phaseo;
$client = new Phaseo();
$response = $client->createChatCompletion([
'model' => 'openai/gpt-6-astra',
'messages' => [[
'role' => 'user',
'content' => 'Write a limerick about lighthouses.',
]],
]);
echo $response['choices'][0]['message']['content'];
require 'phaseo_sdk'
client = PhaseoSdk::Phaseo.new
response = client.create_chat_completion(
model: 'openai/gpt-6-astra',
messages: [{ role: 'user', content: 'Write a limerick about lighthouses.' }]
)
import app.phaseo.sdk.Phaseo;
import java.util.List;
import java.util.Map;
Phaseo client = new Phaseo(System.getenv("PHASEO_API_KEY"));
var response = client.createChatCompletion(Map.of(
"model", "openai/gpt-6-astra",
"messages", List.of(
Map.of("role", "user", "content", "Write a one-line haiku.")
)
));
System.out.println(response.path("choices").path(0).path("message").path("content").asText());
use phaseo::Phaseo;
use serde_json::json;
fn main() -> Result<(), Box<dyn std::error::Error>> {
let client = Phaseo::from_env()?;
let response = client.chat_completions(&json!({
"model": "openai/gpt-6-astra",
"messages": [
{
"role": "system",
"content": "Answer concisely."
},
{
"role": "user",
"content": "What is provider fallback?"
}
]
}))?;
let text = response
.body
.pointer("/choices/0/message/content")
.and_then(|value| value.as_str())
.unwrap_or("");
println!("{text}");
Ok(())
}
| Language | Method | Returns |
|---|---|---|
| TypeScript | client.generateText(request); client.chat.completions.create(request) does the same and switches to streaming when stream is true | ChatCompletionsResponse |
| Python | client.generate_text(request); also client.chat.completions.create(request) | APIResponse dict |
| Go | client.GenerateText(ctx, req), alias CreateChatCompletion; takes a phaseo.ChatCompletionsRequest | map[string]interface{} |
| C# | client.GenerateText(request), alias CreateChatCompletion | Dictionary<string, object>? |
| PHP | $client->generateText($request), alias createChatCompletion() | Array |
| Ruby | client.generate_text(...), alias create_chat_completion | Hash |
| Java | client.createChatCompletion(request); takes a Map or Jackson JsonNode | Jackson JsonNode |
| Rust | client.chat_completions(&request) | PhaseoResponse; the JSON is in body |
choices[0].message.content, with finish_reason and usage alongside.
Stream the response
for await (const chunk of client.streamChat({
model: "openai/gpt-6-astra",
messages: [{ role: "user", content: "Stream a story" }],
})) {
if (chunk.text) process.stdout.write(chunk.text);
}
for chunk in client.stream_chat({
"model": "openai/gpt-6-astra",
"messages": [{"role": "user", "content": "Stream a story"}],
}):
if chunk.get("text"):
print(chunk["text"], end="", flush=True)
import app.phaseo.sdk.Phaseo;
import com.fasterxml.jackson.databind.ObjectMapper;
import java.util.List;
import java.util.Map;
Phaseo client = new Phaseo(System.getenv("PHASEO_API_KEY"));
var payload = Map.of(
"model", "openai/gpt-6-astra",
"messages", List.of(Map.of("role", "user", "content", "Hello")),
"stream", true
);
try (var lines = client.rawClient().requestLines(
"POST", "/chat/completions", null, null,
new ObjectMapper().writeValueAsString(payload)
)) {
lines.forEach(System.out::println);
}
| Language | How to stream |
|---|---|
| TypeScript | client.streamChat(request) yields parsed chunks; client.streamText() yields the raw SSE lines. |
| Python | client.stream_chat(request) yields parsed chunks; client.stream_text() yields the raw SSE lines. |
| Java | createChatCompletion returns one JSON body. Set stream: true and send the request with rawClient().requestLines, which returns SSE lines as they arrive; close it with try-with-resources. |
| Go, C#, PHP, Ruby, Rust | No Chat Completions streaming helper; leave stream unset. In C#, PHP and Ruby, Responses has a streaming method. |
choices, id, …) and adds text (the content added by this chunk), usage and reasoning tokens (reasoningTokens / reasoning_tokens).
Parameters
Field names are the JSON body fields in every SDK. Go’s typedphaseo.ChatCompletionsRequest uses PascalCase struct fields (Model, Messages).
| Group | Fields |
|---|---|
| Required | model; messages with roles system, developer, user, assistant or tool, and content as a string or parts |
| Sampling | temperature (0–2), top_p (0–1), top_k (-1 or more), min_p (0–1), seed, where the model supports them |
| Length and penalties | max_tokens or max_completion_tokens, presence_penalty and frequency_penalty (-2 to 2), repetition_penalty (above 0), stop (string or array) |
| Tools | tools, tool_choice, max_tool_calls, parallel_tool_calls |
| Reasoning | reasoning object or reasoning_effort |
| Log probabilities | logprobs, top_logprobs (0–20) |
| Output | response_format, n (1–16), stream, service_tier, metadata (string values) |
| Gateway | provider routing, usage (include usage), meta (include the gateway meta block) |
Response
ChatCompletionsResponse:
{
"id": "chatcmpl-123",
"object": "chat.completion",
"created": 1677652288,
"model": "openai/gpt-6-astra",
"choices": [
{
"index": 0,
"message": {
"role": "assistant",
"content": "Hello there, how may I assist you today?"
},
"finish_reason": "stop"
}
],
"usage": {
"prompt_tokens": 9,
"completion_tokens": 12,
"total_tokens": 21
}
}
stream: true, the endpoint sends SSE frames that end with data: [DONE]:
data: {"id":"chatcmpl-123","object":"chat.completion.chunk","created":1677652288,"model":"openai/gpt-6-astra","choices":[{"index":0,"delta":{"role":"assistant","content":""},"finish_reason":null}]}
data: {"id":"chatcmpl-123","object":"chat.completion.chunk","created":1677652288,"model":"openai/gpt-6-astra","choices":[{"index":0,"delta":{"content":"Hello"},"finish_reason":null}]}
data: {"id":"chatcmpl-123","object":"chat.completion.chunk","created":1677652288,"model":"openai/gpt-6-astra","choices":[{"index":0,"delta":{},"finish_reason":"stop"}],"usage":{"prompt_tokens":9,"completion_tokens":12,"total_tokens":21}}
data: [DONE]