Plugins, variants & insurance
response-healing repairs malformed JSON (code fences, trailing commas, unquoted keys, missing brackets) on non-streamed json_object / json_schema requests. context-compression drops messages from the middle of the conversation (keeping system prompts and the latest turn, tool calls with their results) when a prompt exceeds the model's context window — on by default for models with 8K context or less; x-ultragpt-compressed-messages reports how many were dropped. Model suffixes pick routing: :nitro fastest provider, :floor cheapest, :exacto most reliable tool calling, :thinking reasoning on. Zero-completion insurance: a request that returns no tokens or ends in an error is not billed.
Code
response = client.chat.completions.create(
model="grok-4.7:nitro", # :nitro fastest, :floor cheapest, :exacto best tool calling,
# :thinking reasoning on, :online web search
messages=long_conversation,
response_format={"type": "json_object"},
extra_body={
"plugins": [
{"id": "response-healing"}, # repair malformed JSON (non-streaming)
{"id": "context-compression"}, # drop middle messages if over the context window
],
"safety_identifier": "user-123", # your end user (shows in /activity?user=)
},
extra_headers={"X-Client-Request-Id": "order-42"}, # echoed back + stored on the generation
)