# Code cannot resolve "#include \<cpr/cpr.h\>" or "#include \<nlohmann/json.hpp\>"

**URL:** <https://forum.codecrafters.io/t/code-cannot-resolve-include-cpr-cpr-h-or-include-nlohmann-json-hpp/15991>\
**Category:** Challenges\
**Tags:** challenge:claude-code\
**Created:** [March 17, 2026, 6:09pm UTC](https://forum.codecrafters.io/t/code-cannot-resolve-include-cpr-cpr-h-or-include-nlohmann-json-hpp/15991 "2026-03-17T18:09:57Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![PabloOliveiraVeizaga](https://yyz1.discourse-cdn.com/flex003/user_avatar/forum.codecrafters.io/pablooliveiraveizaga/32/24182_2.png) [@PabloOliveiraVeizaga](https://forum.codecrafters.io/u/PabloOliveiraVeizaga)\
**Post date:** [March 17, 2026, 6:09pm UTC](https://forum.codecrafters.io/t/code-cannot-resolve-include-cpr-cpr-h-or-include-nlohmann-json-hpp/15991/1 "2026-03-17T18:09:57Z")

</div>

#include \<cpr/cpr.h\>

#include \<nlohmann/json.hpp\>

using json = nlohmann::json;

int main(int argc, char \*argv[]) {

if (argc \< 3 || std::string(argv[1]) != “-p”) {

std::cerr \<\< “Expected first argument to be ‘-p’” \<\< std::endl;

return 1;

}

std::string prompt = argv[2];

if (prompt.empty()) {

std::cerr \<\< “Prompt must not be empty” \<\< std::endl;

return 1;

}

const char \*api\_key\_env = std::getenv(“OPENROUTER\_API\_KEY”);

const char \*base\_url\_env = std::getenv(“OPENROUTER\_BASE\_URL”);

std::string api\_key = api\_key\_env ? api\_key\_env : “”;

std::string base\_url =

base\_url\_env ? base\_url\_env : " [OpenRouter](https://openrouter.ai/api/v1) ";

if (api\_key.empty()) {

std::cerr \<\< “OPENROUTER\_API\_KEY is not set” \<\< std::endl;

return 1;

}

json request\_body = {

```auto
  {"model", "anthropic/claude-haiku-4.5"},

  {"messages", json::array({{{"role", "user"}, {"content", prompt}}})},

  {"tools",

```

json::array(

```auto
       {{{"type", "function"},

         {"function",

          {{"name", "Read"},

           {"description", "Read and return the contents of a file"},

           {"parameters",

            {{"type", "object"},

             {"properties",

              {{"file_path",

                {{"type", "string"},

                 {"description", "The path to the file to read"}}}}},

             {"required", json::array({"file_path"})}}}}}}})}};

```

cpr::Response response =

cpr::Post(cpr::Url{base\_url + “/chat/completions”},

cpr::Header{{“Authorization”, "Bearer " + api\_key},

```auto
                        {"Content-Type", "application/json"}},

```

cpr::Body{request\_body.dump()});

if (response.status\_code != 200) {

std::cerr \<\< "HTTP error: " \<\< response.status\_code \<\< std::endl;

return 1;

}

json result = json::parse(response.text);

if (!result.contains(“choices”) || result[“choices”].empty()) {

std::cerr \<\< “No choices in response” \<\< std::endl;

return 1;

}

json message = result[“choices”][0][“message”];

// Check if there are tool calls

if (message.contains(“tool\_calls”) && !message[“tool\_calls”].empty()) {

```auto
json tool_call = message\["tool_calls"\]\[0\];

```

std::string function\_name = tool\_call[“function”][“name”];

std::string arguments\_str = tool\_call[“function”][“arguments”];

```auto
json arguments = json::parse(arguments_str);

```

if (function\_name == “Read” && arguments.contains(“file\_path”)) {

std::string file\_path = arguments[“file\_path”];

std::ifstream file(file\_path);

if (file.is\_open()) {

std::string content((std::istreambuf\_iterator(file)),

std::istreambuf\_iterator());

std::cout \<\< content;

```auto
  } else {

```

std::cerr \<\< "Failed to open file: " \<\< file\_path \<\< std::endl;

return 1;

```auto
  }

}

```

} else {

```auto
// No tool calls, just print the message content

```

if (message.contains(“content”) && !message[“content”].is\_null()) {

std::cout \<\< message[“content”].getstd::string();

```auto
}

```

}

return 0;

}

---

<div class="post-metadata">

**Author:** ![andy1li](https://yyz1.discourse-cdn.com/flex003/user_avatar/forum.codecrafters.io/andy1li/32/10_2.png) [@andy1li](https://forum.codecrafters.io/u/andy1li)\
**Post date:** [March 17, 2026, 6:09pm UTC](https://forum.codecrafters.io/t/code-cannot-resolve-include-cpr-cpr-h-or-include-nlohmann-json-hpp/15991/2 "2026-03-17T18:09:57Z")

</div>

Hi, thanks for your post!

I’m currently out of the office and will be back on March 23. I’ll get back to you as soon as possible once I return.

---

<div class="post-metadata">

**Author:** ![andy1li](https://yyz1.discourse-cdn.com/flex003/user_avatar/forum.codecrafters.io/andy1li/32/10_2.png) [@andy1li](https://forum.codecrafters.io/u/andy1li)\
**Post date:** [April 9, 2026, 10:32pm UTC](https://forum.codecrafters.io/t/code-cannot-resolve-include-cpr-cpr-h-or-include-nlohmann-json-hpp/15991/3 "2026-04-09T22:32:43Z")

</div>

Hey @PabloOliveiraVeizaga, could you [upload your code to GitHub](https://docs.codecrafters.io/features/publish-to-github) and share the link? It will be much easier to debug if I can run it directly.

---

<div class="post-metadata">

**Author:** ![andy1li](https://yyz1.discourse-cdn.com/flex003/user_avatar/forum.codecrafters.io/andy1li/32/10_2.png) [@andy1li](https://forum.codecrafters.io/u/andy1li)\
**Post date:** [April 13, 2026, 9:12pm UTC](https://forum.codecrafters.io/t/code-cannot-resolve-include-cpr-cpr-h-or-include-nlohmann-json-hpp/15991/4 "2026-04-13T21:12:29Z")

</div>

Closing this thread due to inactivity. If you still need assistance, feel free to reopen or start a new discussion!

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex003/uploads/codecrafters/original/3X/7/0/700657133935c15703e22c7c8870394f6e6dc27d.svg) [@system](https://forum.codecrafters.io/u/system)\
**Post date:** [April 18, 2026, 9:13pm UTC](https://forum.codecrafters.io/t/code-cannot-resolve-include-cpr-cpr-h-or-include-nlohmann-json-hpp/15991/5 "2026-04-18T21:13:24Z")

</div>

This topic was automatically closed 5 days after the last reply. New replies are no longer allowed.
