> For clean Markdown of any page, append .md to the page URL.
> For a complete documentation index, see https://docs.beatapi.io/llms.txt.
> For AI client integration (Claude Code, Cursor, etc.), connect to the MCP server at https://docs.beatapi.io/_mcp/server.

# Create a text chat completion

POST https://api.beatapi.io/v1/chat/completions
Content-Type: application/json

OpenAI Chat Completions-compatible endpoint for existing SDK integrations. Unknown request fields are ignored, as on the OpenAI API; `POST /v1/capabilities/run` refuses them.

Reference: https://docs.beatapi.io/api-reference/gpt-5-6/text/create-chat-completion

## Authentication

- `Authorization` header (bearer token, required) — Send your API key as `Authorization: Bearer <BEATAPI_API_KEY>`.
- `x-api-key` header (required) — Anthropic-compatible API key header. Use a BeatAPI API key.

## Request

### Body (application/json)

This endpoint expects a TextPassthroughRequest.

- `model` (string, required) — Public text model id exposed by BeatAPI. Call GET /v1/models to discover the models enabled for your environment.

## Response

### 200

OpenAI-compatible JSON response or server-sent event stream

- `map from string to any`

## Errors

### 400 Bad Request Error

Malformed JSON or an unsupported field (`bad_request`), or input refused by moderation (`content_policy_violation`). Not retryable unchanged.

- `TextError`

### 401 Unauthorized Error

No API key (`missing_api_key`), or a key that is wrong, expired, disabled or exhausted (`invalid_api_key`).

- `TextError`

### 402 Payment Required Error

Insufficient balance (`insufficient_credits`). The account balance is zero or below the price of this request.

- `TextError`

### 403 Forbidden Error

The key or account is not permitted to use this model (`forbidden`), for example a model that is not available on free credit.

- `TextError`

### 404 Not Found Error

Unknown model (`not_found`). List the enabled models with `GET /v1/models`.

- `TextError`

### 429 Too Many Requests Error

Too many requests (`rate_limit_exceeded`, including the free-model limits). Retry after `Retry-After` seconds.

- `TextError`

### 500 Internal Server Error

Unexpected internal error (`internal_error`). Retryable.

- `TextError`

### 503 Service Unavailable Error

The request could not be completed (`processing_unavailable`, `processing_timeout` or `processing_failed`). Nothing was charged. Retry with backoff.

- `TextError`

## Types

### OpenAITextError

- `error` (OpenAiTextErrorError, required)

### AnthropicTextError

- `type` ("error", required)
- `error` (AnthropicTextErrorError, required)

### OpenAiTextErrorError

- `message` (string, required) — English sentence that states the cause.
- `type` (string, optional)
- `code` (string, optional) — BeatAPI error code, for example `insufficient_credits` or `rate_limit_exceeded`.

### AnthropicTextErrorError

- `type` (string, required)
- `message` (string, required) — English sentence that states the cause.

## Examples

**Request**

```json
{
  "model": "gpt-5.6-terra",
  "messages": [
    {
      "content": "Summarize the attached product requirements into an implementation plan.",
      "role": "user"
    }
  ],
  "stream": true
}
```

**Response**

```json
{}
```

**SDK Code**

```python Text_createChatCompletion_example
import requests

url = "https://api.beatapi.io/v1/chat/completions"

payload = {
    "model": "gpt-5.6-terra",
    "messages": [
        {
            "content": "Summarize the attached product requirements into an implementation plan.",
            "role": "user"
        }
    ],
    "stream": True
}
headers = {
    "Authorization": "Bearer <token>",
    "Content-Type": "application/json"
}

response = requests.post(url, json=payload, headers=headers)

print(response.json())
```

```javascript Text_createChatCompletion_example
const url = 'https://api.beatapi.io/v1/chat/completions';
const options = {
  method: 'POST',
  headers: {Authorization: 'Bearer <token>', 'Content-Type': 'application/json'},
  body: '{"model":"gpt-5.6-terra","messages":[{"content":"Summarize the attached product requirements into an implementation plan.","role":"user"}],"stream":true}'
};

try {
  const response = await fetch(url, options);
  const data = await response.json();
  console.log(data);
} catch (error) {
  console.error(error);
}
```

```go Text_createChatCompletion_example
package main

import (
	"fmt"
	"strings"
	"net/http"
	"io"
)

func main() {

	url := "https://api.beatapi.io/v1/chat/completions"

	payload := strings.NewReader("{\n  \"model\": \"gpt-5.6-terra\",\n  \"messages\": [\n    {\n      \"content\": \"Summarize the attached product requirements into an implementation plan.\",\n      \"role\": \"user\"\n    }\n  ],\n  \"stream\": true\n}")

	req, _ := http.NewRequest("POST", url, payload)

	req.Header.Add("Authorization", "Bearer <token>")
	req.Header.Add("Content-Type", "application/json")

	res, _ := http.DefaultClient.Do(req)

	defer res.Body.Close()
	body, _ := io.ReadAll(res.Body)

	fmt.Println(res)
	fmt.Println(string(body))

}
```

```ruby Text_createChatCompletion_example
require 'uri'
require 'net/http'

url = URI("https://api.beatapi.io/v1/chat/completions")

http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true

request = Net::HTTP::Post.new(url)
request["Authorization"] = 'Bearer <token>'
request["Content-Type"] = 'application/json'
request.body = "{\n  \"model\": \"gpt-5.6-terra\",\n  \"messages\": [\n    {\n      \"content\": \"Summarize the attached product requirements into an implementation plan.\",\n      \"role\": \"user\"\n    }\n  ],\n  \"stream\": true\n}"

response = http.request(request)
puts response.read_body
```

```java Text_createChatCompletion_example
import com.mashape.unirest.http.HttpResponse;
import com.mashape.unirest.http.Unirest;

HttpResponse<String> response = Unirest.post("https://api.beatapi.io/v1/chat/completions")
  .header("Authorization", "Bearer <token>")
  .header("Content-Type", "application/json")
  .body("{\n  \"model\": \"gpt-5.6-terra\",\n  \"messages\": [\n    {\n      \"content\": \"Summarize the attached product requirements into an implementation plan.\",\n      \"role\": \"user\"\n    }\n  ],\n  \"stream\": true\n}")
  .asString();
```

```php Text_createChatCompletion_example
<?php
require_once('vendor/autoload.php');

$client = new \GuzzleHttp\Client();

$response = $client->request('POST', 'https://api.beatapi.io/v1/chat/completions', [
  'body' => '{
  "model": "gpt-5.6-terra",
  "messages": [
    {
      "content": "Summarize the attached product requirements into an implementation plan.",
      "role": "user"
    }
  ],
  "stream": true
}',
  'headers' => [
    'Authorization' => 'Bearer <token>',
    'Content-Type' => 'application/json',
  ],
]);

echo $response->getBody();
```

```csharp Text_createChatCompletion_example
using RestSharp;

var client = new RestClient("https://api.beatapi.io/v1/chat/completions");
var request = new RestRequest(Method.POST);
request.AddHeader("Authorization", "Bearer <token>");
request.AddHeader("Content-Type", "application/json");
request.AddParameter("application/json", "{\n  \"model\": \"gpt-5.6-terra\",\n  \"messages\": [\n    {\n      \"content\": \"Summarize the attached product requirements into an implementation plan.\",\n      \"role\": \"user\"\n    }\n  ],\n  \"stream\": true\n}", ParameterType.RequestBody);
IRestResponse response = client.Execute(request);
```

```swift Text_createChatCompletion_example
import Foundation

let headers = [
  "Authorization": "Bearer <token>",
  "Content-Type": "application/json"
]
let parameters = [
  "model": "gpt-5.6-terra",
  "messages": [
    [
      "content": "Summarize the attached product requirements into an implementation plan.",
      "role": "user"
    ]
  ],
  "stream": true
] as [String : Any]

let postData = JSONSerialization.data(withJSONObject: parameters, options: [])

let request = NSMutableURLRequest(url: NSURL(string: "https://api.beatapi.io/v1/chat/completions")! as URL,
                                        cachePolicy: .useProtocolCachePolicy,
                                    timeoutInterval: 10.0)
request.httpMethod = "POST"
request.allHTTPHeaderFields = headers
request.httpBody = postData as Data

let session = URLSession.shared
let dataTask = session.dataTask(with: request as URLRequest, completionHandler: { (data, response, error) -> Void in
  if (error != nil) {
    print(error as Any)
  } else {
    let httpResponse = response as? HTTPURLResponse
    print(httpResponse)
  }
})

dataTask.resume()
```