# Any OpenAI-compatible tool

Any application, framework, IDE plugin, or agent that targets OpenAI's **Chat Completions** API can point at The Grid. The configuration is always the same three values:

| Setting      | Value                                                                                                                                                                                                                                        |
| ------------ | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| **Base URL** | `https://api.thegrid.ai/v1`                                                                                                                                                                                                                  |
| **API key**  | Your Grid API key from [app.thegrid.ai/profile/api-keys](https://app.thegrid.ai/profile/api-keys)                                                                                                                                            |
| **Model**    | An instrument string from our [nine instruments](/docs/instrument-specifications/current-instruments.md): `text-standard`, `text-prime`, `text-max`, `code-standard`, `code-prime`, `code-max`, `agent-standard`, `agent-prime`, `agent-max` |

If a tool has fields for base URL, API key, and model, and it speaks Chat Completions, you can use The Grid.

## What works: Chat Completions API tools

Our Consumption API implements OpenAI's `chat/completions` interface. That's the surface our suppliers serve and the surface our market is priced against. Any tool that posts to a `chat/completions` endpoint with the OpenAI request body works as long as you set the three values above.

This covers the large majority of OpenAI-compatible tooling today: cross-provider routers, agent frameworks, IDE plugins, eval harnesses, and most application code written against the OpenAI SDK.

## What doesn't work yet: Responses API tools

Tools built on OpenAI's newer **Responses** API (`/v1/responses`) don't work with The Grid yet. That includes Codex (the OpenAI CLI), and any tool that calls `client.responses.create()` or posts to a `responses` endpoint.

The Responses API has a different request and response shape from Chat Completions, and we don't expose a compatible endpoint today. If your tool only targets Responses, it can't run against The Grid right now. If your tool can be configured to use Chat Completions instead (most can), point it at our base URL using the configuration above.

## Tools expose this configuration in three patterns

Most tools fall into one of these patterns.

**Environment variables** (CLI tools, scripts, agents):

```bash
export OPENAI_API_BASE=https://api.thegrid.ai/v1
export OPENAI_API_KEY=your-grid-api-key
```

Then set the model to an instrument string wherever the tool accepts it. Some tools use `OPENAI_BASE_URL` instead of `OPENAI_API_BASE`. Check the tool's docs.

**JSON or YAML config files** (IDE plugins, agent frameworks):

```json
{
  "provider": "openai",
  "base_url": "https://api.thegrid.ai/v1",
  "api_key": "your-grid-api-key",
  "model": "text-prime"
}
```

Field names vary. `base_url`, `baseURL`, `api_base`, and `endpoint` are all common. The values are always the same.

## Popular SDKs

If you're writing custom code, here's how to wire up the most common SDKs against our Consumption API. The same three values apply: base URL, API key, and an instrument string in the `model` field.

{% tabs %}
{% tab title="OpenAI SDK (Python)" %}

```python
from openai import OpenAI

client = OpenAI(
    base_url="https://api.thegrid.ai/v1",
    api_key="your-grid-api-key",
)

response = client.chat.completions.create(
    model="text-prime",
    messages=[{"role": "user", "content": "Hello from The Grid."}],
)
```

{% endtab %}

{% tab title="OpenAI SDK (Node)" %}

```javascript
import OpenAI from "openai";

const client = new OpenAI({
  baseURL: "https://api.thegrid.ai/v1",
  apiKey: "your-grid-api-key",
});

const response = await client.chat.completions.create({
  model: "text-prime",
  messages: [{ role: "user", content: "Hello from The Grid." }],
});
```

{% endtab %}

{% tab title="Vercel AI SDK" %}

```javascript
import { createOpenAICompatible } from "@ai-sdk/openai-compatible";
import { generateText } from "ai";

const grid = createOpenAICompatible({
  name: "the-grid",
  baseURL: "https://api.thegrid.ai/v1",
  apiKey: "your-grid-api-key",
});

const { text } = await generateText({
  model: grid("text-prime"),
  prompt: "Hello from The Grid.",
});
```

{% endtab %}
{% endtabs %}

## What's supported

Through Chat Completions, we serve:

* Streaming (server-sent events)
* Function and tool calling
* Structured outputs (JSON mode and JSON schema)
* System, user, and assistant messages
* Multi-turn conversations
* `max_tokens`, `temperature`, `top_p`, `stop`, and standard generation parameters

## What's not supported

These are OpenAI-specific products, not part of the inference contract:

* The Responses API (`/v1/responses`) and any tool built on it (Codex and similar)
* The Assistants API and Threads
* File uploads and retrieval
* Image generation (DALL-E)
* Audio (Whisper, TTS)
* Embeddings
* Fine-tuning
* Batch API

If a tool requires any of these, those calls go directly to whichever provider offers them. Chat completions still work through The Grid.

## Common gotchas

**Don't add `/chat/completions` to the base URL.** Most clients append the path themselves. The base URL is `https://api.thegrid.ai/v1`, not `https://api.thegrid.ai/v1/chat/completions`. If you set the latter, your requests hit `…/v1/chat/completions/chat/completions` and 404.

**Watch out for tools that auto-append `/v1`.** Some SDKs and tools automatically append `/v1` to whatever base URL you provide. If you set `https://api.thegrid.ai/v1` and the tool adds another `/v1`, your requests hit `https://api.thegrid.ai/v1/v1/chat/completions` and fail with a 404. If your tool does this, set the base URL to `https://api.thegrid.ai` (without `/v1`).

**No trailing slashes.** Use `https://api.thegrid.ai/v1`, not `https://api.thegrid.ai/v1/`. A trailing slash on the base URL causes some clients to construct malformed paths.

**Auth header is `Bearer`, not raw key.** The header is `Authorization: Bearer YOUR_KEY`. The literal word `Bearer`, then a space, then your key. Most SDKs add the prefix automatically. If you're crafting requests by hand and you get a 401, check the header format.

**Use the instrument string in the `model` field, not a model name.** `text-prime` works. `gpt-4o` returns a 404. The full list of [nine instruments](/docs/instrument-specifications/current-instruments.md) lives in the spec docs.

**Some clients follow redirects, some don't.** We use 307 redirects on certain paths. If you're using `curl`, add `-L` to follow them. Most SDKs handle this automatically. See [API reference → Request routing and redirects](/docs/api-reference/request-routing-and-redirects.md) for details.

## Tools built on the Anthropic SDK

The OpenAI-compatible endpoint above works for any tool that speaks `chat/completions`. For tools built around `messages.create()` from the Anthropic SDK, point them at our Messages API beta at `https://messages-beta.api.thegrid.ai/v1` instead. See [Migrating from Anthropic](/docs/integrations-and-best-practices/migrating-from-anthropic.md).

If you set the three values correctly and still get errors, the [Troubleshooting](/docs/integrations-and-best-practices/troubleshooting.md) page has the common ones with fixes.


---

# Agent Instructions: 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:

```
GET https://thegrid.ai/docs/integrations-and-best-practices/any-openai-compatible-tool.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
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.
