# Grok 4.7

> Grok 4.7 API on PoYo. Use Chat Completions at $1.6 input and $4.8 output per million tokens, 20% below official standard rates.

## Overview

- Endpoint: `https://api.poyo.ai/v1/chat/completions`
- Page: https://poyo.ai/models/grok-4-7
- Model page ID: `grok-4-7`
- API model ID: `grok-4.7`
- Category: Chat
- Auth: `Authorization: Bearer $POYO_API_KEY`
- Create a key at https://poyo.ai/dashboard/api-key

This model uses a synchronous chat API. POST the JSON body below. There is no `task_id` and no status polling.

## Pricing

- Input: 320 credits ($1.60) per 1M tokens
- Output: 960 credits ($4.80) per 1M tokens
- Cache Read: 80 credits ($0.400) per 1M tokens

For more details, see https://poyo.ai/models/grok-4-7.

## API Information

POST the JSON body below. Fields are top-level unless noted.

### Request body

- `model` (`ModelEnum`, required):
  xAI Grok model id.
  - Default: `"grok-4.7"`
  - Options: `"grok-4.7"`, `"grok-4.6"`
- `messages` (`list`, required):
  List of conversation messages. Each message contains a `role` and `content`. Use `system` to define model behavior, `user` for user input, and `assistant` for previous model responses in multi-turn conversations.
  - Array of ChatMessage
- `temperature` (`float`, optional):
  Controls output randomness, range 0-2. Lower values such as 0.2 make output more deterministic. Higher values such as 1.8 make output more random. Default: 1.0.
  - Range: `0` to `2`
  - Examples: `1`
- `max_tokens` (`integer`, optional):
  Maximum number of tokens to generate. Different models have different maximum limits.
  - Range: `1` to `+∞`
  - Examples: `256`
- `stream` (`boolean`, optional):
  Whether to use streaming output. `true` returns a streaming response in SSE format. `false` returns the complete response at once. Default: false.
  - Examples: `false`
- `top_p` (`float`, optional):
  Nucleus sampling parameter, range 0-1. Controls diversity of generated text. We recommend using either `top_p` or `temperature`, not both. Default: 1.0.
  - Range: `0` to `1`
  - Examples: `1`
- `frequency_penalty` (`float`, optional):
  Frequency penalty, range -2.0 to 2.0. Positive values reduce the likelihood of repeating the same words. Default: 0.
  - Range: `-2` to `2`
  - Examples: `0`
- `presence_penalty` (`float`, optional):
  Presence penalty, range -2.0 to 2.0. Positive values increase the likelihood of talking about new topics. Default: 0.
  - Range: `-2` to `2`
  - Examples: `0`
- `stop` (`string | array`, optional):
  Stop sequences. Up to 4 sequences where generation will stop when encountered.
  - One of: string | array
- `n` (`integer`, optional):
  Number of completions to generate. Default: 1. Must be a plain number such as `1`; do not use quotes.
  - Range: `1` to `+∞`
  - Examples: `1`

Required Parameters Example:

```json
{
  "model": "grok-4.7",
  "messages": [
    {
      "role": "user",
      "content": "Explain vector databases in one sentence."
    }
  ]
}
```

Full Example:

```json
{
  "model": "grok-4.7",
  "messages": [
    {
      "role": "user",
      "content": "Explain vector databases in one sentence."
    }
  ]
}
```

System prompt:

```json
{
  "model": "grok-4.7",
  "messages": [
    {
      "role": "system",
      "content": "You are a senior Python reviewer. Reply with a numbered list."
    },
    {
      "role": "user",
      "content": "Review: def add(a, b): return a+b"
    }
  ],
  "max_tokens": 512
}
```

Streaming output:

```json
{
  "model": "grok-4.7",
  "messages": [
    {
      "role": "user",
      "content": "Generate 5 short titles about AI agents."
    }
  ],
  "stream": true
}
```

### Output Schema

The response is returned from the same request. There is no separate status endpoint.

Example Response:

```json
{
  "id": "chatcmpl-9876543210",
  "object": "chat.completion",
  "created": 1677652288,
  "model": "grok-4.7",
  "choices": [
    {
      "index": 0,
      "message": {
        "role": "assistant",
        "content": "A vector database stores embeddings and finds the most similar ones quickly."
      },
      "finish_reason": "stop"
    }
  ],
  "usage": {
    "prompt_tokens": 12,
    "completion_tokens": 18,
    "total_tokens": 30
  }
}
```

## Usage Examples

### cURL

```bash
curl --request POST \
  --url https://api.poyo.ai/v1/chat/completions \
  --header "Authorization: Bearer $POYO_API_KEY" \
  --header "Content-Type: application/json" \
  --data '{"model":"grok-4.7","messages":[{"role":"user","content":"Explain vector databases in one sentence."}]}'
```

### Python

```python
import json
import os
import requests

headers = {
    "Authorization": f"Bearer {os.environ['POYO_API_KEY']}",
    "Content-Type": "application/json",
}
payload = json.loads("{\n  \"model\": \"grok-4.7\",\n  \"messages\": [\n    {\n      \"role\": \"user\",\n      \"content\": \"Explain vector databases in one sentence.\"\n    }\n  ]\n}")

response = requests.post("https://api.poyo.ai/v1/chat/completions", headers=headers, json=payload)
response.raise_for_status()
print(response.json())
```

### JavaScript

```javascript
const headers = {
  Authorization: `Bearer ${process.env.POYO_API_KEY}`,
  "Content-Type": "application/json",
};

const response = await fetch("https://api.poyo.ai/v1/chat/completions", {
  method: "POST",
  headers,
  body: JSON.stringify({
  "model": "grok-4.7",
  "messages": [
    {
      "role": "user",
      "content": "Explain vector databases in one sentence."
    }
  ]
}),
});

console.log(await response.json());
```

## Additional Resources

### Documentation

- [Model Playground](https://poyo.ai/models/grok-4-7)
- [API Documentation](https://docs.poyo.ai/api-manual/chat-series/xai)
- [API Documentation (Markdown)](https://docs.poyo.ai/api-manual/chat-series/xai.md)

### Other agent-readable surfaces

- [Platform overview](https://poyo.ai/llms.txt)
- [Documentation index](https://docs.poyo.ai/llms.txt)
- [Full documentation text](https://docs.poyo.ai/llms-full.txt)
- Any other model: `https://poyo.ai/models/<model-id>/llms.txt`
