> ## Documentation Index
> Fetch the complete documentation index at: https://docs.ai-stats.phaseo.app/llms.txt
> Use this file to discover all available pages before exploring further.

# Chat completions

> Call /chat/completions with the Ruby SDK.

**Methods**: `client.generate_text(...)`, `client.create_chat_completion(...)`.

### Example

```ruby theme={null}
require 'ai_stats_sdk'

client = AIStatsSdk::AIStats.new(api_key: ENV.fetch("AI_STATS_API_KEY"))

response = client.create_chat_completion(
  "model" => "openai/gpt-4o-mini",
  messages: [
    { "role" => "user", "content" => "Write a limerick about lighthouses." }
  ],
  "temperature" => 0.5
)
```

### Key parameters

* `model` (required): Target model id.
* `messages` (required): Ordered messages with roles `user`/`system`/`assistant`/`tool`; content as strings.
* Sampling: `temperature` (0–2), `top_p` (0–1), `top_k` (>=1), `seed` (int, optional).
* Length/penalties: `max_output_tokens` (int), `presence_penalty` and `frequency_penalty` (-2 to 2), `stop` (string|string\[]).
* Tools: `tools` (definitions), `tool_choice` (auto/none/specific tool), `max_tool_calls` (int), `parallel_tool_calls` (bool).
* Logprobs: `logprobs` (bool), `top_logprobs` (0–20).
* Output: `response_format` (json/text), `metadata` (object passthrough), `stream` (bool), `service_tier`.
* Gateway extras: `usage` (bool to request usage), `meta` (bool to include meta block).

### Returns

`ChatCompletionsResponse`
