> For the complete documentation index, see [llms.txt](https://docs.usedecentral.org/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.usedecentral.org/integrations/openai-compatible.md).

# OpenAI-Compatible Usage

The Decentral API accepts the same request shape as the OpenAI API and returns the same response shape. If you are already using the OpenAI SDK in Python, TypeScript, or any other language, you can point it at Decentral by changing the base URL and API key.

***

## What is compatible

| Feature                                 | Compatible                              |
| --------------------------------------- | --------------------------------------- |
| `POST /v1/chat/completions`             | Yes, including streaming                |
| `GET /v1/models`                        | Yes, with additional `decentral` fields |
| Streaming (SSE)                         | Yes                                     |
| `max_tokens`, `temperature`, `top_p`    | Yes                                     |
| `stop` sequences                        | Yes                                     |
| `frequency_penalty`, `presence_penalty` | Yes                                     |
| System and multi-turn messages          | Yes                                     |
| Tool / function calling                 | Coming in Phase 2                       |
| Embeddings (`/v1/embeddings`)           | Coming in Phase 2                       |
| Image inputs (`vision`)                 | Coming in Phase 2                       |
| Assistants API                          | No                                      |
| Fine-tuning API                         | No                                      |

***

## Python (OpenAI SDK)

```python
from openai import OpenAI

client = OpenAI(
    base_url="https://api.usedecentral.org/v1",
    api_key="dcntrl_live_your_key_here"
)

# Non-streaming
response = client.chat.completions.create(
    model="qwen3-8b",
    messages=[
        {"role": "system", "content": "You are a concise assistant."},
        {"role": "user", "content": "What is llama.cpp?"}
    ]
)
print(response.choices[0].message.content)

# Streaming
stream = client.chat.completions.create(
    model="llama-3.3-70b",
    messages=[{"role": "user", "content": "Explain zero-knowledge proofs."}],
    stream=True
)

for chunk in stream:
    print(chunk.choices[0].delta.content or "", end="", flush=True)
```

***

## TypeScript / Node.js (OpenAI SDK)

```typescript
import OpenAI from "openai"

const client = new OpenAI({
    baseURL: "https://api.usedecentral.org/v1",
    apiKey: "dcntrl_live_your_key_here"
})

// Non-streaming
const response = await client.chat.completions.create({
    model: "qwen3-8b",
    messages: [
        { role: "system", content: "You are a concise assistant." },
        { role: "user", content: "What is llama.cpp?" }
    ]
})
console.log(response.choices[0].message.content)

// Streaming
const stream = await client.chat.completions.create({
    model: "llama-3.3-70b",
    messages: [{ role: "user", content: "Explain zero-knowledge proofs." }],
    stream: true
})

for await (const chunk of stream) {
    process.stdout.write(chunk.choices[0]?.delta?.content ?? "")
}
```

***

## Environment variable setup

Use an environment variable for your API key. Never hardcode it.

```bash
export DECENTRAL_API_KEY="dcntrl_live_your_key_here"
```

```python
import os
from openai import OpenAI

client = OpenAI(
    base_url="https://api.usedecentral.org/v1",
    api_key=os.environ["DECENTRAL_API_KEY"]
)
```

```typescript
const client = new OpenAI({
    baseURL: "https://api.usedecentral.org/v1",
    apiKey: process.env.DECENTRAL_API_KEY!
})
```

***

## Accessing on-chain receipt data

The Decentral API adds extra response headers that the OpenAI SDK does not surface by default. If you need the Solana transaction signatures for verification, you can access them by inspecting the raw HTTP response.

```python
import httpx

response = httpx.post(
    "https://api.usedecentral.org/v1/chat/completions",
    headers={"Authorization": f"Bearer {api_key}"},
    json={
        "model": "qwen3-8b",
        "messages": [{"role": "user", "content": "Hello"}]
    }
)

job_id = response.headers.get("x-decentral-job-id")
settlement_tx = response.headers.get("x-decentral-settlement-tx")
print(f"Job: {job_id}")
print(f"Settlement tx: https://explorer.solana.com/tx/{settlement_tx}")
```

If you want typed access to receipts, structured streaming, and wallet-native auth, use the \[JavaScript SDK]\(

) or the \[Python usage guide]\().

***

## Selecting a model

Decentral's model IDs differ from OpenAI's. Call `GET /v1/models` to see the current list. Common substitutions:

| OpenAI model    | Comparable Decentral model | Notes                               |
| --------------- | -------------------------- | ----------------------------------- |
| `gpt-4o`        | `llama-3.3-70b`            | Strong general reasoning            |
| `gpt-4o-mini`   | `qwen3-8b`                 | Fast, cheap, capable for most tasks |
| `gpt-3.5-turbo` | `mistral-7b`               | Fastest, lowest cost                |
| none            | `deepseek-r1`              | Long-form reasoning, math, code     |

***

## Differences from the OpenAI API

**Credits instead of billing.** Decentral uses a prepaid credit balance rather than a monthly invoice. Credits must be funded before making API calls.

**On-chain settlement headers.** Every response includes `x-decentral-job-id` and `x-decentral-tx-signature` headers. These have no equivalent in the OpenAI API.

**No rate limits from a policy team.** Capacity is dynamically priced. If no workers are available for your model, you get a `503` with a `retry_after` value. There is no queue or throttling for well-behaved clients.

**Model deprecation policy.** Model IDs are stable. When a model is retired, the Decentral community votes it off the recommended list with advance notice. The ID remains valid until deprecated, not until a two-week warning period expires.


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://docs.usedecentral.org/integrations/openai-compatible.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
