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

# OpenAI Responses API

> Give OpenAI's models access to Tako as a tool through the Responses API

Use **OpenAI's own models** (e.g. `gpt-5.5`) with **Tako attached as a tool** through the [Responses API](https://platform.openai.com/docs/api-reference/responses). OpenAI is the model; Tako is the tool it calls when a question needs grounded, real-time data — and the answer comes back with the interactive Tako cards behind it.

<Info>
  Here, OpenAI's model does the reasoning and Tako provides the data. Want **Tako itself as the model** (`tako-answer` / `tako-agent`) instead? See the [OpenAI-Compatible API](/documentation/integrations/openai-compatible-api). For the Chat Completions equivalent of this page, see [OpenAI Tool Calling](/documentation/integrations/openai-tool-calling).
</Info>

You'll need two keys:

* **`OPENAI_API_KEY`** — from the OpenAI dashboard (authenticates the OpenAI client).
* **`TAKO_API_KEY`** — your [Tako API key](https://developer.tako.com/console/api-keys) (`tako_sk_…`), used to reach Tako.

```bash theme={null}
pip install openai
export OPENAI_API_KEY=<your openai key>
export TAKO_API_KEY=<your tako key>
```

## Attach Tako via MCP

The simplest path: hand the Responses API Tako's hosted [MCP server](/documentation/integrations/mcp-server) as a remote tool. OpenAI discovers Tako's tools (`tako_search`, `tako_answer`, …), calls them when useful, and runs the whole loop server-side — no tool-handling code on your end.

<CodeGroup>
  ```python Python theme={null}
  import os
  from openai import OpenAI

  client = OpenAI(api_key=os.environ["OPENAI_API_KEY"])

  response = client.responses.create(
      model="gpt-5.5",
      tools=[
          {
              "type": "mcp",
              "server_label": "tako",
              "server_description": "Real-time, grounded data and charts from Tako.",
              "server_url": "https://mcp.tako.com/mcp",
              "authorization": os.environ["TAKO_API_KEY"],   # your tako_sk_… token
              "require_approval": "never",
              "allowed_tools": ["tako_search", "tako_answer"],
          }
      ],
      input="How has Nvidia's revenue grown since 2015?",
  )

  print(response.output_text)
  ```

  ```bash cURL theme={null}
  curl https://api.openai.com/v1/responses \
    -H "Authorization: Bearer $OPENAI_API_KEY" \
    -H "Content-Type: application/json" \
    -d '{
      "model": "gpt-5.5",
      "tools": [{
        "type": "mcp",
        "server_label": "tako",
        "server_url": "https://mcp.tako.com/mcp",
        "authorization": "'"$TAKO_API_KEY"'",
        "require_approval": "never",
        "allowed_tools": ["tako_search", "tako_answer"]
      }],
      "input": "How has Nvidia revenue grown since 2015?"
    }'
  ```
</CodeGroup>

`authorization` carries your `tako_sk_…` token (OpenAI forwards it to Tako). `require_approval: "never"` lets the model call Tako without an approval round-trip; `allowed_tools` restricts which Tako tools it may use (omit it to allow all). See [MCP Server](/documentation/integrations/mcp-server) for the full tool list and auth options.

<Note>
  Tako's MCP server speaks Streamable HTTP at `https://mcp.tako.com/mcp`. OpenAI's Responses runtime connects to it directly, so this works from any OpenAI client without running anything locally.
</Note>

## Alternative: define Tako as a function tool

If you can't use a remote MCP server, register Tako as a plain **function tool** and run the call yourself with the [Tako Python SDK](https://pypi.org/project/tako-sdk/). You handle the `function_call` → execute → `function_call_output` loop (the same pattern as [OpenAI Tool Calling](/documentation/integrations/openai-tool-calling), adapted to the Responses API's flat tool shape).

```python Python theme={null}
import json
import os
from openai import OpenAI
from tako.lib import Tako
from tako.models.search_request import SearchRequest

client = OpenAI(api_key=os.environ["OPENAI_API_KEY"])
tako = Tako(api_key=os.environ["TAKO_API_KEY"])

tools = [
    {
        "type": "function",
        "name": "tako_answer",
        "description": (
            "Answer a factual or quantitative question with data grounded in Tako "
            "knowledge cards and the web. Returns a written answer plus the backing cards."
        ),
        "parameters": {
            "type": "object",
            "properties": {
                "query": {"type": "string", "description": "Natural-language question, e.g. 'US GDP growth last year'."}
            },
            "required": ["query"],
        },
    }
]

messages = [{"role": "user", "content": "How has Nvidia's revenue grown since 2015?"}]
response = client.responses.create(model="gpt-5.5", tools=tools, input=messages)
messages += response.output   # carry the model's function_call items into the next turn

for item in response.output:
    if item.type == "function_call" and item.name == "tako_answer":
        args = json.loads(item.arguments)
        result = tako.answer(SearchRequest(query=args["query"]))
        cards = [{"title": c.title, "embed_url": c.embed_url} for c in (result.cards or [])]
        messages.append({
            "type": "function_call_output",
            "call_id": item.call_id,
            "output": json.dumps({"answer": result.answer, "cards": cards}),
        })

final = client.responses.create(model="gpt-5.5", tools=tools, input=messages)
print(final.output_text)
```

## How results and cards flow back

Either way, OpenAI's model writes the final prose into `response.output_text`. The **Tako cards** — each with an `embed_url` you can render or link — come back alongside it:

* **MCP:** each Tako call appears in `response.output` as an `mcp_call` item (with `name`, `arguments`, and the tool's `output`); the card URLs are in that output. A leading `mcp_list_tools` item lists the Tako tools that were loaded.
* **Function tool:** you control the payload — return the cards (`embed_url`, `image_url`, …) from the Tako SDK in your `function_call_output`, and the model can cite them in its answer.

See [Knowledge Cards](/documentation/getting-started/what-is-tako/knowledge-cards) for how to embed a returned card.
