codingBy HowDoIUseAI Team

How to build an AI agent that researches Polymarket bets with Kimi K2

Learn how to pair Kimi K2 with coding agents like OpenCode to research prediction markets, build models, and spot mispriced Polymarket bets.

A clip has been making the rounds showing someone pointing an open-source Chinese model at Polymarket and walking away with a return that sounds made up. Whether or not you believe the exact percentage, the underlying workflow is real, repeatable, and something you can set up this afternoon: a coding agent, a frontier open-weight model, and a prediction market with an open API.

This isn't about blindly trusting an AI to place bets for you. It's about using an agent to do the tedious research work — building probability models, tracking lineup news, monitoring odds movement — faster than a human ever could, so you can make a more informed decision on where the market is mispricing an outcome. Here's how the pieces fit together and how to build your own version of it.

What is Kimi K2 and why does it matter for this kind of work?

Kimi K2 is Moonshot AI's open-weight large language model, and it's built specifically with this kind of task in mind. It's a state-of-the-art mixture-of-experts language model with 32 billion activated parameters and 1 trillion total parameters, achieving exceptional performance across frontier knowledge, reasoning, and coding tasks while being meticulously optimized for agentic capabilities.

That last part — "optimized for agentic capabilities" — is the key detail. The model was designed for tool use, reasoning, and autonomous problem-solving, which means it's not just answering questions in a chat window. It can call functions, hit APIs, write and execute code, and chain multiple steps together without a human clicking "continue" every time.

Since the original K2 release, Moonshot has kept shipping. In November 2025, Moonshot released Kimi K2 Thinking, an open-source update designed for advanced reasoning and agentic tasks, and it can execute 200-300 sequential tool calls autonomously. Then in July 2026, the company pushed things further. Moonshot released Kimi K3, the first open model to reach 2.8 trillion parameters, designed for long-horizon coding, knowledge work, and reasoning, and it outperformed Claude Opus 4.8 max and GPT-5.5 high on benchmarks. You can grab an API key and read the technical specs directly at the Kimi API Platform documentation or browse the open weights on Moonshot AI's GitHub.

The reason this matters for market research specifically: long tool-call chains and huge context windows mean the model can pull in news articles, injury reports, historical odds data, and your own notes in a single session, then reason across all of it instead of losing the thread after a few paragraphs.

What is OpenCode and how does it connect a model to real tasks?

You can't just paste a prompt into a chatbot and expect it to run live research loops. You need an agent framework that gives the model hands — the ability to browse, run code, hit APIs, and remember what it did five steps ago. That's where OpenCode comes in.

OpenCode is an open source AI coding agent, available as a terminal-based interface, desktop app, or IDE extension. Critically, it isn't locked to one AI company. With OpenCode you can use any LLM provider by configuring their API keys. That's the whole trick behind pointing it at Kimi instead of the usual suspects — you're not stuck with whatever model the tool ships with by default.

Here's how to set it up:

  1. Install OpenCode using the install script or a package manager. You can install it via Homebrew (brew install anomalyco/tap/opencode), npm (npm install -g opencode-ai), or Go.
  2. Run opencode auth login to add a credential. OpenCode is powered by the provider list at Models.dev, so you can use opencode auth login to configure API keys for any provider you'd like.
  3. Grab a Kimi API key from Moonshot's platform and paste it in when prompted, the same way you would for Z.AI or any other provider — run opencode auth login, select the provider, and enter your API key.
  4. Run opencode models to confirm Kimi shows up in your provider list, then start a session pointed at it.
  5. Once you're in a session, use /plan mode first if you want the model to sketch out a research approach before it starts writing code or pulling data — this avoids burning tool calls on a half-formed idea.

For non-interactive scripting — useful if you want to schedule research runs automatically — you can run opencode in non-interactive mode by passing a prompt directly, which is useful for scripting, automation, or when you want a quick answer without launching the full TUI. That's exactly what you'd want for something like an automated pre-match check that runs every morning during a tournament.

How does Polymarket's API fit into the picture?

None of this works without a way to actually see live odds and pull historical data programmatically. That's where Polymarket's official documentation comes in — it's the primary resource for anyone building around the platform's markets.

Polymarket's docs are built around the world's largest prediction market, offering APIs, SDKs, and tools for prediction market developers so you can make your first API request in minutes, fetch market data, place orders, and redeem winning positions. Under the hood, Polymarket is a decentralized prediction markets platform that enables users to trade on the outcomes of future events using blockchain technology. Prices aren't arbitrary — they're a direct read on crowd sentiment. A "Yes" trading at $0.74 means the crowd gives a 74% chance the event happens, not a guaranteed return.

The platform actually exposes several distinct services rather than one monolithic API. The API is organized into multiple services — notably the Gamma market data API, the CLOB trading API, and the Data API — and each interacts with Polymarket's underlying smart contracts on the Polygon blockchain. For research purposes, you mostly care about Gamma. It's a comprehensive API that developers and analysts use to retrieve live market data, event listings, price information, order book snapshots, and user positions, offering a robust interface for building applications and conducting research on prediction markets.

If you want to actually execute trades rather than just pull data, you'll need the trading side of things. Once set up, the Polymarket API exposes endpoints like /markets for listings, /orders for trades, and /prices for snapshots, all secured via HMAC signatures — a process that takes under 15 minutes. Keep in mind there are practical limits on how hard you can hit it: rate limits apply, typically 100 requests per minute for free tiers, but they scale with trading volume.

What does an actual research workflow look like?

Put the three pieces together and here's a realistic workflow, using a sports match as an example (this mirrors the kind of scenario mapping you'd want before a big tournament game):

  1. Feed the agent the market. Point your OpenCode session at a specific Polymarket event URL or its Gamma API endpoint and ask Kimi to summarize the current odds, volume, and recent price movement.
  2. Have it build scenario branches. Ask it to map out conditional outcomes — for example, "if the starting lineup changes, how would that shift the implied probability?" This is exactly the kind of multi-branch reasoning agentic models are good at, since they can hold several hypothetical paths in context at once.
  3. Pull in live news. Give the agent web search or an MCP tool connection so it can check injury reports, team news, or breaking headlines right before the event starts, rather than relying on stale training data.
  4. Cross-reference against the crowd price. The real value isn't the model guessing an outcome — it's comparing its own probability estimate against what the market is already pricing in, and flagging the gap. AI tools don't predict outcomes; they help process information faster, scanning news, scoring sentiment, and flagging mispricings before a human would catch them.
  5. Log everything. Have the agent write its reasoning, sources, and final probability estimate to a file every time, so you can review its track record later instead of just trusting vibes.

If you want to go further, you can wire this up with a dedicated integration rather than raw API calls. Sim's Polymarket tool documentation shows one way to plug market data straight into an agent workflow, and there are several MCP servers built specifically for this, including one that retrieves real-time and historical data from the Polymarket prediction market API, offering a standardized interface for accessing market information, current prices, and historical price trends.

Should you actually trust an AI-generated prediction market call?

Be honest about what these models can and can't do. They're excellent at synthesizing large volumes of information quickly, spotting a scenario you hadn't considered, and doing the grunt work of tracking odds movement across dozens of markets at once. What they can't do is guarantee an outcome — a 74% implied probability still loses 26% of the time, and no amount of agentic tool-calling changes that math.

Treat an AI research agent the way you'd treat a very fast, very well-read research assistant: useful for narrowing down where to look and building a probability estimate, not a replacement for your own judgment on where to actually put money. The viral return numbers make for a great headline. The actual skill worth building is the workflow — and that part you can start testing today with a free OpenCode install and a Kimi API key.