Response consumption
POST /v1/chat/completions returns an OpenAI chat.completion object. Read it the same way you read OpenAI. Fields from ChatCompletionResponse in protocol/src/openai.rs:
| field | type | notes |
|---|---|---|
id | string | Completion identifier |
object | string | Typically "chat.completion" |
created | integer | Unix timestamp (seconds) |
model | string | Model that produced the completion |
choices[] | array | Each item has index, message, finish_reason |
usage | object, optional | prompt_tokens, completion_tokens, total_tokens |
from token_gateway import BuyerAuth, BuyerTokenGateway
gw = BuyerTokenGateway("http://127.0.0.1:8080", buyer=BuyerAuth("sk-buyer"))
completion = gw.chat_completions(
model="gpt-4",
messages=[{"role": "user", "content": "hello"}],
)
content = completion.choices[0].message.content
print(content)
stream: true exists on the request (see chat_completions_stream in sdks/consistency/fixtures/calls.json). End-to-end SSE consumption is on the buyer flow.